更新 2
ユーザーが ViewController1 のボタンをタップした後、アプリをモーダルに表示するとアプリがクラッシュします。私のストーリーボードでは、標準のpresent modally
セグエ セットを使用して、UISearchBar
. 毎回失敗です。
ただし、私AppDelegate
の場合、ウィンドウrootViewController
を同じ UINavController/UITableViewController に設定すると、すべてが期待どおりに機能します。
何らかの理由で、セグエ経由で移行してから UISearchBar を操作すると、クラッシュが発生します。
更新 1
1 つの文字をタップすると、次のエラーが表示されます。
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
テーブル内のデータをフィルタリングするためUISearchController
にiOS8の新しいを使用しています。UISearchBar
をアクティブにするUISearchBar
と、最初の文字を入力するとすぐにアプリがクラッシュします (興味深いことに、オンスクリーン キーボードはシミュレーターに表示されませんが、それは関係ないと思います)。
物事を絞り込むために、私は何もレンダリングしないUIViewController
ように、私のほとんどすべてをコメントしました。各メソッドが呼び出されたときにログに記録できるようにUITableView
実装UISearchControllerDelegate
しました。UISearchBarDelegate
ただし、最初の文字を入力した後、コンソール メッセージが表示されません。どこにブレークポイントを設定できるかさえわかりません。
これが私が得るクラッシュです:
-[NSNull length]: unrecognized selector sent to instance 0x107602ce0
私のファイルのどこにも長さを呼び出していないことに注意してください。舞台裏に何かあるのですが、何が何だかわかりません。
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;
}
リクエストに応じて、ここに私のデリゲート メソッドを示します (最初の文字を入力した後に何かが呼び出されるかどうかを確認するためだけに実装されていますが、そうではありません)。
#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__);
}