1

我想在 UITableViewCell 的 datailTextLabel 中设置一个值。如果代码运行,应用程序就会崩溃。

这是错误:fatal error: unexpectedly found nil while unwrapping an Optional value

这是发生错误的方法:

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

    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell

    cell.detailTextLabel!.text = "Date"      //error occurs

    return cell
}

可能有用的信息: https ://www.dropbox.com/s/240sy3k1ic2hu0q/Bildschirmfoto%202015-02-28%20um%2021.03.35.png?dl=0

4

1 回答 1

0

利用:

let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell

此外,无需强制打开它。即使detailTextLabel存在,我也会使用cell.detailTextLabel?.text = "Date"以确保您的单元格是一种支持detailTextLabel. IE。细节左,细节右,副标题。

于 2015-02-28T20:06:53.933 回答