Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by fluidsonic for Defining 'UITableViewCell' variable in Swift 2.0

If you really want to use the outdated method tableView.dequeueReusableCellWithIdentifier(_:) you can do it like this:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier) ?? UITableViewCell(style: .Default, reuseIdentifier: simpleTableIdentifier)
    cell.textLabel?.text = dwarves[indexPath.row]

    return cell
}

But you should preferably use dequeueReusableCellWithIdentifier(_:forIndexPath:) which never returns nil.
It is used along with registerClass(_:forCellReuseIdentifier:) and registerNib(_:forCellReuseIdentifier:).


Viewing all articles
Browse latest Browse all 4

Trending Articles