Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 字幕表视图单元格_Ios_Tableview_Cell_Subtitle - Fatal编程技术网

Ios 字幕表视图单元格

Ios 字幕表视图单元格,ios,tableview,cell,subtitle,Ios,Tableview,Cell,Subtitle,我正在尝试使用字幕样式在单元格标题中获取两个文本。我尝试将“cell.textlab!.text=data.valueForKeyPath(“divelocation,divenumber”)作为?字符串”,但没有成功 有人能帮忙吗?谢谢 override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell { /

我正在尝试使用字幕样式在单元格标题中获取两个文本。我尝试将“cell.textlab!.text=data.valueForKeyPath(“divelocation,divenumber”)作为?字符串”,但没有成功

有人能帮忙吗?谢谢

   override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell {


    // Configure the cell...

    let CellID: NSString = "Cell"
    var cell: UITableViewCell = tableView?.dequeueReusableCellWithIdentifier(CellID as String)! as! UITableViewCell

    if let ip = indexPath{

        var data: NSManagedObject = myList[ip.row] as! NSManagedObject
        cell.textLabel!.text = data.valueForKeyPath("divelocation, divenumber") as? String

        var ddate = data.valueForKeyPath("divedate") as! String
        var dnumber = data.valueForKeyPath("divenumber") as! String

        cell.detailTextLabel!.text = "\(dnumber) date: \(ddate)"
    }
    return cell
}

您必须将样式设置为
UITableViewCellStyle。Subtitle

override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell {


// Configure the cell...

let CellID: NSString = "Cell"
var cell: UITableViewCell = tableView?.dequeueReusableCellWithIdentifier(CellID as String)! as! UITableViewCell

if let ip = indexPath{

    var data: NSManagedObject = myList[ip.row] as! NSManagedObject
    var divelocation = data.valueForKeyPath("divelocation") as! String
    var divenumber = data.valueForKeyPath("divenumber") as! String
    cell.textLabel!.text = "\(divelocation)" + "\(divenumber)"

    var ddate = data.valueForKeyPath("divedate") as! String
    var dnumber = data.valueForKeyPath("divenumber") as! String

    cell.detailTextLabel!.text = "\(dnumber) date: \(ddate)"
}
return cell
}

当初始化单元格时,必须像这样初始化

var cell_ : UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("CELL_ID") as? UITableViewCell
    if(cell_ == nil)
    {
        cell_ = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "CELL_ID")
    }

很抱歉,我不知道如何设置标签中的文本。@Scubadivingfool我明白了,编辑了答案。希望对您有所帮助。
cell.textLabel!。text=“\(divelocation),\(divenumber)”
。发生了什么?您是否正确地看到了
textlab
,并且只有
detailtextlab
没有出现?您在原型单元中指定了什么单元类型?如果我有cell.textLabel!。text=data.valueForKeyPath(“divelocation”)作为?字符串,然后一切工作,我只想添加潜水位置旁边的潜水编号。我正在原型中使用字幕单元格cell@Scubadivingfool您的密钥路径不应该是“divelocation.divenumber”吗?好的,让我们后退一步。您问题的标题表示副标题中有问题(即
detailtextlab
)。但是在阅读了你的评论之后,我正在重新阅读你的问题,看起来问题出在
textlab
而不是
detailtextlab
。因此,请编辑您的问题并澄清问题的具体内容。坦白地说,keypath
divelocation,divenumber
在我看来非常可疑:你想在那里做什么?这两个字段是分开的吗?为什么不像处理
divedate
divenumber
那样处理它呢?不相关,但是为什么表视图和索引路径变量是可选的呢?您可以保存对非可选文件的展开。哈哈,说一个人“必须”那样做有点强。是的,如果不使用原型,也不使用标识符注册NIB或类,则必须这样做。坦率地说,这种手动实例化单元的模式已不再是常见的做法(如果您希望这样做,则完全可以接受)。不用说,这不太可能是OP的问题,否则他的强制解包会导致他的应用程序崩溃,如果发生这种情况,他肯定会告诉我们。好吧,让你通过编程管理所有单元格的创建,nib有时会做奇怪的事:P