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。すなわち。詳細左、詳細右、サブタイトル。

于 2015-02-28T20:06:53.933 に答える