2011-09-04 137 views
0

我想我的第一個UINavigationController應用程序,它現在崩潰。如果我註釋掉以navController開頭的行,我不會崩潰,但如果該應用程序無法正常工作。UINavigationController錯誤崩潰我的應用程序

(注:我的環境是IOS 4.2和3.2的Xcode)

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    WpglViewController *firstViewController = [[WpglViewController alloc] init];  

    navController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 

    [firstViewController release]; 

    [window addSubview:navController.view]; 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

這裏是崩潰信息。有人能指引我朝着正確的方向嗎?謝謝您的幫助。

2011-09-04 07:59:49.309 wpgl[7302:207] -[WpglViewController title]: unrecognized selector sent to instance 0x4b134c0 
2011-09-04 07:59:49.313 wpgl[7302:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WpglViewController title]: unrecognized selector sent to instance 0x4b134c0' 
*** Call stack at first throw: 

(
    0 CoreFoundation      0x00ecdbe9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00cc25c2 objc_exception_throw + 47 
    2 CoreFoundation      0x00ecf6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x00e3f366 ___forwarding___ + 966 
    4 CoreFoundation      0x00e3ef22 _CF_forwarding_prep_0 + 50 
    5 UIKit        0x00375781 -[UINavigationController pushViewController:transition:forceImmediate:] + 743 
    6 UIKit        0x0036e4a0 -[UINavigationController pushViewController:animated:] + 62 
    7 UIKit        0x00370d98 -[UINavigationController initWithRootViewController:] + 78 
    8 wpgl        0x00001df9 -[wpglAppDelegate application:didFinishLaunchingWithOptions:] + 146 
    9 UIKit        0x002b81fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 
    10 UIKit        0x002ba55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439 
    11 UIKit        0x002c4db2 -[UIApplication handleEvent:withNewEvent:] + 1533 
    12 UIKit        0x002bd202 -[UIApplication sendEvent:] + 71 
    13 UIKit        0x002c2732 _UIApplicationHandleEvent + 7576 
    14 GraphicsServices     0x016e4a36 PurpleEventCallback + 1550 
    15 CoreFoundation      0x00eaf064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    16 CoreFoundation      0x00e0f6f7 __CFRunLoopDoSource1 + 215 
    17 CoreFoundation      0x00e0c983 __CFRunLoopRun + 979 
    18 CoreFoundation      0x00e0c240 CFRunLoopRunSpecific + 208 
    19 CoreFoundation      0x00e0c161 CFRunLoopRunInMode + 97 
    20 UIKit        0x002b9fa8 -[UIApplication _run] + 636 
    21 UIKit        0x002c642e UIApplicationMain + 1160 
    22 wpgl        0x00001d44 main + 102 
    23 wpgl        0x00001cd5 start + 53 
) 
terminate called after throwing an instance of 'NSException' 

在我WpglViewController.h文件我有以下聲明:

@interface WpglViewController : NSObject <UIApplicationDelegate> 

{ 
    UILabel *servingsLabel; 
    UILabel *quantityLabel; 
    UINavigationController *navigationController; 
} 

@property (nonatomic, retain) IBOutlet UILabel *servingsLabel; 
@property (nonatomic, retain) IBOutlet UILabel *quantityLabel; 
@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) UINavigationController *navigationController; 

@end 

,並在我的WpglViewController我有以下聲明:

#import "WpglViewController.h" 

@implementation WpglViewController 

@synthesize servingsLabel; 
@synthesize quantityLabel; 
@synthesize navigationController; 

回答

3

WpglViewController需要是UIViewController的子類。

這個異常說WpglViewController不響應它在UIViewController中所期望的標題方法。

+0

progmr, 我更新了頭部的信息以顯示我的聲明。讓我知道如果我錯過了什麼。 – padapa

+0

您的視圖控制器不是視圖控制器。它需要是UIViewController的子類,你有它作爲NSObject的子類。 – progrmr

+0

是的,我修正了這個問題,但從未發現問題,所以我開始了一個新項目,現在它似乎正常工作。我不確定是什麼被損壞或在哪裏。感謝您的幫助。 :) – padapa

-2

無論有沒有這樣的類作爲WpglViewController或者你沒有導入它或最可能你沒有initiliaze它與一個筆尖名稱。 WpglViewController是一個類,你必須在另一個類中的initiliazation內指定一個nib WpglViewController * firstViewController = [[WpglViewController alloc] initWithNibName:@「WpglViewController nib名稱,它可能是WpglViewController,除非你改變它不要把eh .xib擴展名」] ;

1
2011-09-04 07:59:49.309 wpgl[7302:207] -[WpglViewController title]: unrecognized selector sent to instance 0x4b134c0 

此消息說明了一切:您WpglViewController沒有實現方法「標題」,也許你忘了@synthesize在.m文件的屬性?

0

檢查[WpglViewController title]顯然問題出在這裏,也許你是在同一個班的init裏面調用這個方法。

0

確保您的WpglViewControllerUIViewController繼承。