Reference from UITableViewCell to parent UITableView?

前端 未结 7 1730
有刺的猬
有刺的猬 2020-11-29 04:02

Is there any way to access the owning UITableView from within a UITableViewCell?

7条回答
  •  清歌不尽
    2020-11-29 04:52

    You have to add a reference back to the UITableView when you construct the table view cell.

    However, almost certainly what you really want is a reference to your UITableViewController... that requires the same thing, set it as a delegate of the cell when you build the cell and hand it to the table view.

    An alternate approach if you are wiring up actions is to build the cells in IB, with the table view controller as the files owner - then wire up buttons in the cell to actions in the table view controller. When you load the cell xib with loadNibNamed, pass in the view controller as the owner and the button actions will be wired back to the table view controller.

提交回复
热议问题