0

雖然我的應用程序正常啓動且沒有錯誤,但當我嘗試單擊某個按鈕以顯示另一個視圖時,應用程序關閉。
在調試器控制檯,這是顯示:從按鈕調用子視圖:應用程序關閉

"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

您的第二個代碼塊與第一個代碼塊相同。你想編輯它嗎?此外,使用代碼格式 - 只需突出顯示代碼,然後在窗體頂部選擇大括號。 – Jim

+0

謝謝,對不起。 – mentorship

回答

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; 

這將不解決您的issue..if您有任何問題理解的東西讓我知道。

+0

嘗試更改該行[window addSubview .... to self.window.rootViewController = self.navigationController; – Shubhank

+0

嘗試通過您的代碼breakpointing ..檢查哪一行它成功通過,並在哪一行崩潰? – Shubhank

+0

這就是它在斷點下所說的全部......我不知道它是什麼意思。 – mentorship

0

它看起來像你釋放你的導航控制器,然後試圖添加一個視圖控制器。

相關問題