How to know the UITableview row number

前端 未结 10 1711
粉色の甜心
粉色の甜心 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:08

    A colleague suggested the following, which I made into a UITableView category:

    +(UITableViewCell*)findParentCellForSubview:(UIView*)view
    {
        while (([view isKindOfClass:[UITableViewCell class]] == NO) && ([view superview] != nil))
            view = [view superview];
    
        if ([view superview] != nil)
            return (UITableViewCell*)view;
    
        return nil;
    }
    

    Still hackly - but it works.

提交回复
热议问题