输入UISearchBar会导致我的应用崩溃 [英] Typing in UISearchBar crashes my app

查看:174
本文介绍了输入UISearchBar会导致我的应用崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新2

在用户点击ViewController1中的按钮后,我的应用程序以模态方式呈现时崩溃。在我的故事板中,我有一个标准的现在模态 segue设置为弹出包含 UISearchBar 的UINavController / UITableViewController。这种情况每次都失败。

My app is crashing when presenting it modally after a user taps a button in ViewController1. In my storyboard, I have a standard present modally segue set to pop up the UINavController/UITableViewController containing the UISearchBar. That's failing every time.

然而,在我的 AppDelegate 中,如果我设置窗口的 rootViewController 到同一个UINavController / UITableViewController,一切都按预期工作。

However, in my AppDelegate, if I set the window's rootViewController to the same UINavController/UITableViewController, everything works as expected.

出于某种原因,通过segue转换然后代理UISearchBar导致崩溃。

For some reason transitioning via segue and then acting the UISearchBar is causing the crash.

更新1

点击时我现在收到以下错误一封信:

I'm now receiving the following error when tapping one letter:

2015-02-03 12:23:35.262 Afar D[28348:2740681] -[NSNull length]: unrecognized selector sent to instance 0x10e352ce0
2015-02-03 12:23:40.313 Afar D[28348:2740681] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x10e352ce0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010e0a9f35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010dd42bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010e0b104d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010e00927c ___forwarding___ + 988
    4   CoreFoundation                      0x000000010e008e18 _CF_forwarding_prep_0 + 120
    5   CoreFoundation                      0x000000010df89a7b CFStringCompareWithOptionsAndLocale + 219
    6   Foundation                          0x000000010d6822b7 -[NSString compare:options:range:] + 29
    7   UIKit                               0x000000010c5f53b4 -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 224
    8   UIKit                               0x000000010c53c12e -[UIResponder(Internal) _keyCommandForEvent:] + 285
    9   UIKit                               0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
    10  UIKit                               0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
    11  UIKit                               0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
    12  UIKit                               0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
    13  UIKit                               0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
    14  UIKit                               0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
    15  UIKit                               0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
    16  UIKit                               0x000000010c3d8f0a -[UIApplication _handleKeyUIEvent:] + 126
    17  UIKit                               0x000000010c5c7fcc -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 66
    18  UIKit                               0x000000010c75bbb7 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 3611
    19  UIKit                               0x000000010c75a8e5 -[UIKeyboardLayoutStar touchUp:executionContext:] + 1374
    20  UIKit                               0x000000010c5d531b __28-[UIKeyboardLayout touchUp:]_block_invoke + 242
    21  UIKit                               0x000000010cb23914 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
    22  UIKit                               0x000000010c5d521c -[UIKeyboardLayout touchUp:] + 252
    23  UIKit                               0x000000010c5d5cc6 -[UIKeyboardLayout touchesEnded:withEvent:] + 319
    24  UIKit                               0x000000010c40b308 -[UIWindow _sendTouchesForEvent:] + 735
    25  UIKit                               0x000000010c40bc33 -[UIWindow sendEvent:] + 683
    26  UIKit                               0x000000010c3d89b1 -[UIApplication sendEvent:] + 246
    27  UIKit                               0x000000010c3e5a7d _UIApplicationHandleEventFromQueueEvent + 17370
    28  UIKit                               0x000000010c3c1103 _UIApplicationHandleEventQueue + 1961
    29  CoreFoundation                      0x000000010dfdf551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    30  CoreFoundation                      0x000000010dfd541d __CFRunLoopDoSources0 + 269
    31  CoreFoundation                      0x000000010dfd4a54 __CFRunLoopRun + 868
    32  CoreFoundation                      0x000000010dfd4486 CFRunLoopRunSpecific + 470
    33  GraphicsServices                    0x000000010fc109f0 GSEventRunModal + 161
    34  UIKit                               0x000000010c3c4420 UIApplicationMain + 1282
    35  My App                              0x000000010a5e1c63 main + 115
    36  libdyld.dylib                       0x000000010e75a145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我正在使用iOS8的新 UISearchController 管理 UISearchBar 以过滤表中的数据。如果我激活 UISearchBar ,一旦我输入第一个字母,应用程序就会崩溃(有趣的是,屏幕键盘没有出现在模拟器中,但我不知道我认为这是相关的。)

I'm using iOS8's new UISearchController to manage a UISearchBar for filtering data in a table. If I activate the UISearchBar, the app crashes as soon as I type the first letter (Interestingly, the on-screen keyboard doesn't appear in the Simulator, but I don't think that's related).

为了缩小范围,我几乎评论了我的 UIViewController 这样 UITableView 什么都不呈现。我已经实现了 UISearchControllerDelegate UISearchBarDelegate ,这样我就可以在调用每个方法时进行记录。但是,在输入第一个字母后,我没有收到控制台消息。我甚至不知道在哪里设置断点。

In order to narrow things down, I've commented almost everything out of my UIViewController so that the UITableView renders nothing. I've implemented UISearchControllerDelegate and UISearchBarDelegate just so I can log when each method gets called. However, after typing the first letter, I receive no console messages. I don't even know where I could set a breakpoint.

这是我得到的崩溃:

-[NSNull length]: unrecognized selector sent to instance 0x107602ce0

注意在我的文件中没有任何地方,我在任何事情上都称呼长度。幕后的东西是,但我无法弄清楚是什么。

Note that nowhere in my file am I calling length on anything. Something behind the scenes is, but I can't figure out what.

这是设置UISearchController的代码:

Here's my code to set up the UISearchController:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchResultsUpdater = self;
    self.searchController.definesPresentationContext = true;
    self.searchController.hidesNavigationBarDuringPresentation = false;
    [self.searchController.searchBar sizeToFit];
    self.tableView.tableHeaderView = self.searchController.searchBar;

    self.searchController.searchBar.delegate = self;
    self.searchController.delegate = self;
}

根据请求,这是我的委托方法(仅用于查看是否有任何内容键入第一个字母后调用 - 他们没有):

By request, here are my delegate methods (implemented just to see if anything gets called after typing the first letter - they don't):

#pragma mark - UISearchResultsUpdating

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

#pragma mark - UISearchControllerDelegate

- (void)didDismissSearchController:(UISearchController *)searchController
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)didPresentSearchController:(UISearchController *)searchController
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)presentSearchController:(UISearchController *)searchController
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)willDismissSearchController:(UISearchController *)searchController
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)willPresentSearchController:(UISearchController *)searchController
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

#pragma mark - UISearchBarDelegate

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
    return true;
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
    return true;
}

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
    return true;
}

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}


推荐答案

燃烧一整天后挣扎有了它,它归结为一个完全不相关的问题:一个损坏的故事板。

After burning an entire day struggling with this, it came down to a totally unrelated problem: a corrupted storyboard.

这个SO问题建议找出哪个场景已损坏并重新创建它。不幸的是我无法确定,所以经过一些试验和错误,它最终成为我的故事板中的初始视图控制器,恰好是 UINavigationController 。我删除了它,把它重新加入,一切都是金色的。

This SO question recommended finding which scene was corrupt and recreating it. Unfortunately there was no way for me to determine that, so after some trial and error, it ended up being the initial view controller in my storyboard, which happened to be a UINavigationController. I deleted that, added it back in, and everything is golden.

这篇关于输入UISearchBar会导致我的应用崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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