iOS7中的UITableViewCell indexPath崩溃 [英] UITableViewCell indexPath crash in iOS7

查看:262
本文介绍了iOS7中的UITableViewCell indexPath崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UITableViewController 中有 UITableViewCell
在我的单元格中有一个按钮,当您点击时会带您到另一个视图,并带有 prepareforsegue
prepareForSegue 我这样做:

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 prepareforsegue. In prepareForSegue I do this:

if ([[segue identifier] isEqualToString:@"MySegue"])
{
    UITableViewCell *cell = (UITableViewCell*) [[sender superview] superview];
    UITableView *table = (UITableView*)[[[sender superview] superview] superview];
    NSIndexPath *indexPath = [table indexPathForCell:cell]; 
}

好的!一切都运作良好。但是现在我已经用iOS7升级了xCode,当我点击单元格中的按钮时,一个错误出现给我,我不知道如何解决它:

Ok! Everything has always worked well. But now that I've upgraded xCode with iOS7, when I click on the button located in the cell, an error presents itself to me, and I don't know how to solve it:

[UITableViewCell indexPathForCell:]: unrecognized selector sent to instance 0x9e160b0
2013-09-20 16:30:44.427 MyApp[8212:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell indexPathForCell:]: unrecognized selector sent to instance 0x9e160b0'
*** First throw call stack:
(
    0   CoreFoundation                      0x024475e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01a5d8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x024e4903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0243790b ___forwarding___ + 1019
    4   CoreFoundation                      0x024374ee _CF_forwarding_prep_0 + 14
    5   MyApp                              0x0004bc01 -[NewsTableViewController prepareForSegue:sender:] + 3441
    6   UIKit                               0x00af69cc -[UIStoryboardSegueTemplate _perform:] + 156
    7   UIKit                               0x00af6a59 -[UIStoryboardSegueTemplate perform:] + 115
    8   libobjc.A.dylib                     0x01a6f874 -[NSObject performSelector:withObject:withObject:] + 77
    9   UIKit                               0x005c4c8c -[UIApplication sendAction:to:from:forEvent:] + 108
    10  UIKit                               0x005c4c18 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    11  UIKit                               0x006bc6d9 -[UIControl sendAction:to:forEvent:] + 66
    12  UIKit                               0x006bca9c -[UIControl _sendActionsForEvents:withEvent:] + 577
    13  UIKit                               0x006bbd4b -[UIControl touchesEnded:withEvent:] + 641
    14  UIKit                               0x00936d7f _UIGestureRecognizerUpdate + 7166
    15  UIKit                               0x00601d4a -[UIWindow _sendGesturesForEvent:] + 1291
    16  UIKit                               0x00602c6a -[UIWindow sendEvent:] + 1030
    17  UIKit                               0x005d6a36 -[UIApplication sendEvent:] + 242
    18  UIKit                               0x005c0d9f _UIApplicationHandleEventQueue + 11421
    19  CoreFoundation                      0x023d08af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    20  CoreFoundation                      0x023d023b __CFRunLoopDoSources0 + 235
    21  CoreFoundation                      0x023ed30e __CFRunLoopRun + 910
    22  CoreFoundation                      0x023ecb33 CFRunLoopRunSpecific + 467
    23  CoreFoundation                      0x023ec94b CFRunLoopRunInMode + 123
    24  GraphicsServices                    0x032c89d7 GSEventRunModal + 192
    25  GraphicsServices                    0x032c87fe GSEventRun + 104
    26  UIKit                               0x005c394b UIApplicationMain + 1225
    27  MyApp                              0x00002cfb main + 235
    28  libdyld.dylib                       0x01f42725 start + 0
    29  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

应用程序崩溃的行是:

    NSIndexPath *indexPath = [table indexPathForCell:cell]; }


推荐答案

在iOS7中 UITableViewWrapperView UITableViewCell 的超级视图,这意味着另一个超级视图:

In iOS7 UITableViewWrapperView is the superview of UITableViewCell, which means another superview for you:

iOS7:

UITableView *tableView = (UITableView *)cell.superview.superview;

iOS6

UITableView *tableView = (UITableView *)cell.superview;

您可以在此处找到另一项更改:

Another change you can find it here:

似乎你的代码:UITableView table =(UITableView )[[[sender superview] superview] superview];返回 UITableViewCell 而不是 UITableView

seems your code: UITableView table = (UITableView)[[[sender superview] superview] superview]; returns a UITableViewCell not a UITableView.

请尝试以下操作:

UITableView *table = (UITableView*)[[[[[sender superview] superview] superview] superview] superview];

这篇关于iOS7中的UITableViewCell indexPath崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆