How to know the UITableview row number

前端 未结 10 1839
粉色の甜心
粉色の甜心 2020-11-22 11:28

I have a UITableViewCell with UISwitch as accessoryview of each cell. When I change the value of the switch in a cell, how can I know in which row

10条回答
  •  抹茶落季
    2020-11-22 12:00

    I prefer using subviews, if you know your layout it's generally super simple and 1 line short...

        NSIndexPath *indexPath = [tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
    

    Thats it, if its more nested, add in more superviews.

    Bit more info:

    all you are doing is asking for the parent view and its parent view which is the cell. Then you are asking your tableview for the indexpath of that cell you just got.

提交回复
热议问题