0

I don't understand why I can't set the title of my UIButton. It crashes here:

enter image description here

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    if(section == 0) {
        let view = UIView()
        view.alpha = 0
        return kTableHeaderShouldStickToTop ? view : carouselViewController.view
    } else {
        let cell = tableView.dequeueReusableCellWithIdentifier("NewsFeedSectionHeaderCell") as! NewsFeedSectionHeaderCell
        cell.delegate = self
        cell.dataSource = self

        cell.followingButton.setTitle("test", forState: .Normal)
        return cell
    }
}

It is connected in my .xib file:

enter image description here

Iyyappan Ravi
  • 3,205
  • 2
  • 16
  • 30
Rutger Huijsmans
  • 2,330
  • 2
  • 30
  • 67

1 Answers1

0

Please check whether we can take cell object in viewForHeaderInSection: method because as per my knowledge viewForHeaderInSection: is called before cellForRowAtIndexPath. Put a breakpoint at

let cell = tableView.dequeueReusableCellWithIdentifier("NewsFeedSectionHeaderCell") as! NewsFeedSectionHeaderCell

And check from the variable View (left to console where we see logs) or hover over this object to see whether this object is nil or not. It will be nil so it raising the exception.

user4261201
  • 2,324
  • 19
  • 26