No index path for table cell being reused

前端 未结 13 1504
执念已碎
执念已碎 2021-02-04 05:18

This started to happen out of the blue. Any ideas: Code:

CUSTOMCLASSNAME (I have replaced the actual class name as it contains the name of the client.)

Initialis

13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 05:58

    I found this warning during my viewForHeaderInSection implementation.

    This is my solution in Swift 2.x:

    let headerView = self.tableView.dequeueReusableCellWithIdentifier("MyCell") as! MyCell
    let containerView = UIView(frame:headerView.frame)
    headerView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
    headerView.myLabel.text = "section title 1"
    containerView.addSubview(headerView)
    return containerView
    

    This is the Swift 3 version:

    let headerView = self.tableView.dequeueReusableCell(withIdentifier: "MyCell") as! MyCell
    let containerView = UIView(frame:headerView.frame)
    headerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    headerView.myLabel.text = "section title 1"
    containerView.addSubview(headerView)
    return containerView
    

提交回复
热议问题