好的,所以我正在尝试使用MasterDetail模板在选项卡控制器中嵌入我已创建的整个应用程序。
我收到错误,因为app委托将上下文放在顶视图控制器上或类似的东西上,我不确定将其重定向到哪里。
现在,我搜索过它并找到了这个:iOS MasterDetail app inside TabController - where to start?
但这不是特别有用,因为解决方案只会产生更多错误。
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
错误日志:
2013-11-07 07:47:01.217 RoslynCAD[4491:70b] -[UITabBarController topViewController]: unrecognized selector sent to instance 0x9d72fe0
2013-11-07 07:47:01.220 RoslynCAD[4491:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController topViewController]: unrecognized selector sent to instance 0x9d72fe0'
*** First throw call stack:
(
0 CoreFoundation 0x01cf75e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01a7a8b6 objc_exception_throw + 44
2 CoreFoundation 0x01d94903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01ce790b ___forwarding___ + 1019
4 CoreFoundation 0x01ce74ee _CF_forwarding_prep_0 + 14
5 RoslynCAD 0x0000b9f6 -[AppDelegate application:didFinishLaunchingWithOptions:] + 278
6 UIKit 0x007e2355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
7 UIKit 0x007e2b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
8 UIKit 0x007e73a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
9 UIKit 0x007fb87c -[UIApplication handleEvent:withNewEvent:] + 3447
10 UIKit 0x007fbde9 -[UIApplication sendEvent:] + 85
11 UIKit 0x007e9025 _UIApplicationHandleEvent + 736
12 GraphicsServices 0x0262e2f6 _PurpleEventCallback + 776
13 GraphicsServices 0x0262de01 PurpleEventCallback + 46
14 CoreFoundation 0x01c72d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
15 CoreFoundation 0x01c72a9b __CFRunLoopDoSource1 + 523
16 CoreFoundation 0x01c9d77c __CFRunLoopRun + 2156
17 CoreFoundation 0x01c9cac3 CFRunLoopRunSpecific + 467
18 CoreFoundation 0x01c9c8db CFRunLoopRunInMode + 123
19 UIKit 0x007e6add -[UIApplication _run] + 840
20 UIKit 0x007e8d3b UIApplicationMain + 1225
21 RoslynCAD 0x000147ed main + 141
22 libdyld.dylib 0x0308370d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
和
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
更新: 我编辑了我的代码:
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)[tabController.viewControllers objectAtIndex:0];
controller.managedObjectContext = self.managedObjectContext;
我现在收到此错误
2013-11-10 00:37:03.455 RoslynCAD[6783:70b] -[UINavigationController setManagedObjectContext:]: unrecognized selector sent to instance 0x9e54c40
(lldb)
答案 0 :(得分:1)
错误很明显。你这样做:
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
错误来自第二行。该错误告诉您navigationController
实际上是UITabBarController
,而不是UINavigationController
。
你想:
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
// Get what you need from the tab controller