cant return cell in cellForRowAtIndexPath

后端 未结 4 1674
北荒
北荒 2021-01-15 15:44

i\'m trying to return different cells in a tableView. Normally in this case i would return different cells and then return nil at the bottom, but in this case it gives me an

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-15 15:52

    You mustn't return nil from cellForRowAtIndexPath. You always should return a valid cell.

     var cell: UITableViewCell!
    

    This line of code doesn't create any cell, it just a UITableViewCell variable with nil content, you have to assign a value to it:

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

提交回复
热议问题