虽然我的应用程序正常启动并且没有错误,但当我尝试单击按钮以显示另一个视图时,应用程序将关闭。
在调试器控制台上,这是显示:
"SEM2REDO[13487:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4ea5be0>"
然后第二次单击它,会出现,然后应用程序取消。
2012-01-24 11:46:37.549 SEM2REDO[13591:b603] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/margueriteoquinn/Library/Application Support/iPhone Simulator/4.3/Applications/F2B86CC5-C700-414E-9030-17E94535EB1A/SEM2REDO.app> (loaded)' with name 'SelectView''
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc95a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f1d313 objc_exception_throw + 44
2 CoreFoundation 0x00d81ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x00d81e6a +[NSException raise:format:] + 58
4 UIKit 0x004b40fa -[UINib instantiateWithOwner:options:] + 2024
5 UIKit 0x004b5ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
6 UIKit 0x0036b628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
7 UIKit 0x00369134 -[UIViewController loadView] + 120
8 UIKit 0x0036900e -[UIViewController view] + 56
9 UIKit 0x00367482 -[UIViewController contentScrollView] + 42
10 UIKit 0x00377f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
11 UIKit 0x00376555 -[UINavigationController _layoutViewController:] + 43
12 UIKit 0x00377870 -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
13 UIKit 0x0037232a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
14 UIKit 0x00379562 -[UINavigationController pushViewController:transition:forceImmediate:] + 932
15 UIKit 0x003721c4 -[UINavigationController pushViewController:animated:] + 62
16 SEM2REDO 0x00002590 -[SEM2REDOViewController chooseFirstMeeting:] + 252
17 UIKit 0x002b94fd -[UIApplication sendAction:to:from:forEvent:] + 119
18 UIKit 0x00349799 -[UIControl sendAction:to:forEvent:] + 67
19 UIKit 0x0034bc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
20 UIKit 0x0034a7d8 -[UIControl touchesEnded:withEvent:] + 458
21 UIKit 0x002ddded -[UIWindow _sendTouchesForEvent:] + 567
22 UIKit 0x002bec37 -[UIApplication sendEvent:] + 447
23 UIKit 0x002c3f2e _UIApplicationHandleEvent + 7576
24 GraphicsServices 0x01721992 PurpleEventCallback + 1550
25 CoreFoundation 0x00daa944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
26 CoreFoundation 0x00d0acf7 __CFRunLoopDoSource1 + 215
27 CoreFoundation 0x00d07f83 __CFRunLoopRun + 979
28 CoreFoundation 0x00d07840 CFRunLoopRunSpecific + 208
29 CoreFoundation 0x00d07761 CFRunLoopRunInMode + 97
30 GraphicsServices 0x017201c4 GSEventRunModal + 217
31 GraphicsServices 0x01720289 GSEventRun + 115
32 UIKit 0x002c7c93 UIApplicationMain + 1160
33 SEM2REDO 0x00001a70 main + 102
34 SEM2REDO 0x00001a01 start + 53
)
terminate called throwing an exception
我不知道这意味着什么,但我真的需要一些帮助。这是我实施的一些有用的委托方法
@synthesize window;
@synthesize navController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
SEM2REDOViewController *firstController = [[SEM2REDOViewController alloc]
initWithNibName:@"SEM2REDOViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:firstController];
[self setNavController:navigationController];
[window addSubview:[navigationController view]];
[navigationController release];
[firstController release];
return YES;
}
这是我的SEM2REDOViewController中显示第二个视图的方法
- (IBAction)chooseFirstMeeting:(id)sender {
SelectRotationController *selectView = [[SelectRotationController alloc]
initWithNibName:@"SelectView" bundle:[NSBundle mainBundle]];
[selectView.navigationItem setTitle:@"Select First Meeting"];
[self.navigationController pushViewController:self.selectRotationController animated:YES];
self.selectRotationController = selectView;
[selectView release];
}
如果这是一个简单的问题,我很抱歉:我是一名高中学生,试图对编程进行独立研究,因此非常感谢任何帮助。
答案 0 :(得分:0)
看起来您正在发布导航控制器,然后尝试向其添加视图控制器。
答案 1 :(得分:0)
[self.window makeKeyAndVisible];
SEM2REDOViewController *firstController = [[SEM2REDOViewController alloc] initWithNibName:@"SEM2REDOViewController" bundle:nil]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstController];
[self setNavController:navigationController];
[window addSubview:[navigationController view]];
[navigationController release]; [firstController release];
return YES;
将其更改为
SEM2REDOViewController *firstController = [[[SEM2REDOViewController alloc] initWithNibName:@"SEM2REDOViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc]initWithRootViewController: firstController]autorelease];
[window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
这将解决您的问题..如果您有任何问题,了解某些事情让我知道。