Get section number in custom cell button action

后端 未结 5 1205
北恋
北恋 2021-01-13 23:42

I have a tableView dynamically populated with custom cells in several sections.

In my CustomCell class I have an @IBAction for a custom checkbox button in the cell.

5条回答
  •  别那么骄傲
    2021-01-13 23:56

    One of the ways, suppose you have custom cell and button inside a cell ... Usual pattern would be: (if you're using table view with datasource) when configuring the cell inside:

    - (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    you can set:

    cell.button.tag = sectionIndex
    

    So in:

    func checkboxButton(sender: CheckBox) { ...
    

    sender.tag would be sectionIndex

    Hope you got the idea.

提交回复
热议问题