UITableViewCell indexPath crash in iOS7

后端 未结 6 2037
不知归路
不知归路 2020-12-06 07:38

I\'ve a UITableViewCell in a UITableViewController. In my cell there is a button that when you click takes you to another view with a

6条回答
  •  粉色の甜心
    2020-12-06 08:29

    Apple change the UITableViewCell hierarchy in iOS 7

    Using iOS 6.1 SDK

    
       | 
       |    | 
    

    Using iOS 7 SDK

    
       | 
       |    | 
       |    |    | 
    

    So if you want to get indexpath at button index then use following code Using iOS 6 or later SDK

    UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
        NSIndexPath *clickedButtonPath = [book_table indexPathForCell:clickedCell];
        NSLog(@"index=%@",clickedButtonPath);
    

    Using iOS 7 or 7+ SDK

    UITableViewCell *clickedCell = (UITableViewCell *)[[[sender superview] superview]superview];
        NSIndexPath *clickedButtonPath = [book_table indexPathForCell:clickedCell];
        NSLog(@"index=%ld",(long)clickedButtonPath.item);
    

提交回复
热议问题