How do I retrieve UITableView row number of a UISwitch?

前端 未结 6 1149
你的背包
你的背包 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条回答
  •  梦毁少年i
    2021-01-13 07:12

    for iOS6+ you could maintain a NSMutableArray queuedSwitches

    in -tableView:cellForrowAtIndexPath: you would take a switch, if not empty and places it on the custom cell and assign it to a property. If empty you create a new one.

    in -tableView:didEndDisplayingCell:forRowAtIndexPath: you would add it to quededSwitches and remove it from it cell.

    This will just allocate enough switches for visible cells and reuse them.

    the switches are all wired up to one action.

    -(void)switchAction:(UISwitch *)switch 
    {
        NSIndexPath *indexPath = [self.tableView indexPathForCell:[switch superView]];
    
        //…
    }
    

提交回复
热议问题