0

I have created two different classes of UITableViewButtons to use within the same UITableView/UITableViewController. Both classes have corresponding XIB/NIB Files and subclass UITableViewCell. However on the dequeueReusableCellWithIdentifier (either pointsCell or cell, same error) the app attempts to show and UITableView, leaving it black and crashing on the dequeueReusableCellWithIdentifier line with EXC_BREAKPOINT (code=1, subcode=0x1006fe528)...

This is the first time that I have attempted to add a custom cell to a uitableview, so not sure exactly what I'm doing, however I did follow a tutorial so have a general idea of the concept. New->add file->new swift file->subclassed uuitableviewcell, included XIB->then added the outlets as necessary. Also here is my exact code that causes the issue:

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

     // Configure the cell...



    if indexPath.row == 0 {
        //customize first one with custom data
        let pointsCell:PointsTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as PointsTableViewCell
        let points = NSUserDefaults.standardUserDefaults().objectForKey("points") as Int
        pointsCell.pointsLabel.text = "Points: \(points)"


        return pointsCell
    }


    //otherwise customize the rest normal
    let cell:StoreTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as StoreTableViewCell




    return cell
}
Alex Atwater
  • 151
  • 1
  • 15
  • Any exception message? For example [`Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'`](http://stackoverflow.com/questions/12737860/assertion-failure-in-dequeuereusablecellwithidentifierforindexpath) – Matthias Bauch Mar 06 '15 at 06:20
  • Also: You can't use the same reuse identifier for two different cell classes. – Matthias Bauch Mar 06 '15 at 06:22
  • I literally couldn't get it to throw me an error. I keep hitting continue on the debugger and it refused to spit out anything (i even turned the exception breaker off) – Alex Atwater Mar 06 '15 at 21:55
  • Actually just checked it today, threw "*** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-3318.16.25/UITableView.m:6116" – Alex Atwater Mar 06 '15 at 21:59

1 Answers1

-1

dequeueReusableCellWithIdentifier will return nil if you don't create cell at first,the function is used for reuse

  • Wrong. `dequeueReusableCellWithIdentifier:forIndexPath:` is guaranteed to return a valid cell. If there is no valid cell it will throw an exception. It will never return nil. – Matthias Bauch Mar 06 '15 at 06:16