tableview - 无法识别的选择器didSelectRowAtIndexPath [英] tableview - unrecognized selector didSelectRowAtIndexPath

查看:169
本文介绍了tableview - 无法识别的选择器didSelectRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在选择tableView中的内容时崩溃了。这不是100%可重复,但它经常发生。

I have been having an issue with my app crashing on selecting something in the tableView. This is not 100% reproducible, but it happens relatively often.

我的EventListViewController类(UITableViewController的子类)内部发生了什么,我覆盖了didSelectRowAtIndexPath函数,因为我是使用此类中的搜索栏,我希望它只在您不搜索时选择。

What happens is inside my EventListViewController class (a subclass of UITableViewController), I overwrite the didSelectRowAtIndexPath function because I am using a search bar in this class as well, and I want it to only select when you are not searching.

代码如下所示:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(!searching)
        [super tableView:tableView didSelectRowAtIndexPath:indexPath];
}

然而,当它崩溃时,我会在异常中断,这就是消息I get,在调用超级函数的行上:

However, when it crashes, I break on exception and this is the message I get, on the line that calls the super function:

[EventListViewController tableView:didSelectRowAtIndexPath:]: unrecognized selector sent to instance 0xa648e50

我在调试器上打印了一些东西,这一切对我来说都很好看:

I printed out some stuff on the debugger and it all looks fine to me:

(lldb) po 0xa648e50
(int) $1 = 174362192 <EventListViewController: 0xa648e50>

(lldb) po self
(EventListViewController *) $2 = 0x0a648e50 <EventListViewController: 0xa648e50>

(lldb) po tableView
(UITableView *) $3 = 0x070fd400 <UITableView: 0x70fd400; frame = (0 0; 320 367); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x6e46750>; contentOffset: {-0, -0}>

(lldb) po indexPath
(NSIndexPath *) $4 = 0x06e8caf0 <NSIndexPath 0x6e8caf0> 2 indexes [1, 1]

(tableView有2个部分,第2个部分有2个条目)

(The tableView has 2 sections,and the second section has 2 entries)

任何人都有任何想法发生了什么?如果您需要更多信息,请告诉我。

Anyone have any Idea what is happening? let me know if you need any more information.

注意:经过更多调查后我发现这是100%可重现的,具有以下步骤:
1:加载应用程序,然后单击两个条目之一。
2:回到tableView控制器
3:点击以下两个条目,在白色空间中不应该有一个单元格
该应用程序将崩溃,但请注意indexPath并没有说它试图选择一个超出tableView边界的单元格,只是因为tableView didSelectRowAtIndexPath方法不存在

Note: after more investigation I have found that this is 100 % reproducible with the following steps: 1: load the app, and click on either of the two entries. 2: Go back to the tableView controller 3: tap BELOW both of the entries, in the white space where there shouldn't be a cell The app will crash, but notice that the indexPath doesn't say its trying to select a cell that is outside the bounds of the tableView, just that the tableView didSelectRowAtIndexPath method doesn't exist

推荐答案

tableView:didSelectRowAtIndexPath:中调用 super 是不必要的。如果我没记错的话, UITableViewController 不提供该方法的默认实现。因此,您对super的调用会导致崩溃。

The call to super in tableView:didSelectRowAtIndexPath: is unnecessary. If I remember correctly, UITableViewController does not provide a default implementation of that method. Thus, your call to super results in a crash.

这篇关于tableview - 无法识别的选择器didSelectRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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