How do I retrieve UITableView row number of a UISwitch?

前端 未结 6 1115
你的背包
你的背包 2021-01-13 06:18

I have tried several approaches posted here, but I cannot get my table full of switches to return an index value for the cell of the changed switch. I am creating the view c

6条回答
  •  余生分开走
    2021-01-13 06:58

    You could create a subclass of UISwitch and add an indexPath property, then just set the indexPath in cellForRowAtIndexPath:

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        SwitchCell *returnCell = [tableView dequeueReusableCellWithIdentifier:@"SwitchCell" forIndexPath:indexPath];
        returnCell.switch.indexPath = indexPath;
    
        return returnCell;
    }
    

提交回复
热议问题