Calling -[UINavigationBar setItem:animated:]
on a navigation bar that is being managed by a UINavigationController
is disallowed (and newly enforced) in iOS 7.1
iOS 7.1 Crash: -[UINavigationBar setItems:animated:]
-
13-06-2023 - |
Question
I'm experiencing a crash that is brand new across all iPhone devices with iOS 7.1 and I'm wondering if others have seen the same.
Date/Time: 2014-03-11 11:46:00.795 -0700
OS Version: iOS 7.1 (11D167)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 6
Last Exception Backtrace:
0 CoreFoundation 0x2d4dbefe __exceptionPreprocess + 126
1 libobjc.A.dylib 0x37c70ce2 objc_exception_throw + 32
2 CoreFoundation 0x2d4dbe40 +[NSException raise:format:] + 106
3 UIKit 0x2fe319a0 -[UINavigationBar setItems:animated:] + 98
4 Document 0x97aa6 -[FHHorizontalSplitViewController setVisibility:animated:] (FHHorizontalSplitViewController.m:233)
5 Document 0x98882 __44-[FHHorizontalSplitViewReplaceSegue perform]_block_invoke (FHHorizontalSplitViewController.m:450)
6 Document 0x9814a __72-[FHHorizontalSplitViewController _changeViewFramesAnimated:completion:]_block_invoke (FHHorizontalSplitViewController.m:335)
7 UIKit 0x2fd43788 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 278
8 UIKit 0x2fd433d2 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 172
9 UIKit 0x2fd432ea -[UIViewAnimationState animationDidStop:finished:] + 60
10 QuartzCore 0x2f98de06 CA::Layer::run_animation_callbacks(void*) + 228
11 libdispatch.dylib 0x38159d3a _dispatch_client_callout + 16
12 libdispatch.dylib 0x3815c6be _dispatch_main_queue_callback_4CF + 272
13 CoreFoundation 0x2d4a6674 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 2
14 CoreFoundation 0x2d4a4f40 __CFRunLoopRun + 1302
15 CoreFoundation 0x2d40f7a4 CFRunLoopRunSpecific + 518
16 CoreFoundation 0x2d40f586 CFRunLoopRunInMode + 100
17 GraphicsServices 0x3237c6ce GSEventRunModal + 132
18 UIKit 0x2fd6e88c UIApplicationMain + 1130
19 Document 0x80dbe main (main.m:12)
The code in question (FHHorizontalSplitViewController
) is a custom UIViewController
container that is installed in a UINavigationController
. The gist is it's splits the top and bottom halves of the iPhone screen and selections in the top half expands or contracts the bottom half. When a child-view controller has been expanded to fill the screen, the container asks it for its UINavigationItem
and sets the navigation bar item.
The interesting thing is this crash is new on iOS 7.1; it works fine on 6.x and 7.0.x.
Have others seen new crashes in this method call that didn't happen before?
The crashing call site:
UINavigationController *navVC = self.navigationController;
if (navVC) {
NSMutableArray *navigationItems = [NSMutableArray arrayWithArray:navVC.navigationBar.items;
NSInteger lastItem = [navigationItems count] - 1;
navigationItems[lastItem] = [self navigationItem];
[navVC.navigationBar setItems:navigationItems animated:YES];
}
Solution