2012-03-02 71 views
0

我是新來的objective-c,我目前正在開發iOS應用程序。 我有一個按鈕,我打電話給SettingsButton,這是一個自定義的UIView對象。 當我按下此按鈕時,調用FileOwner「ViewController.m」的Touch Up Inside處理程序,稍後將在NavigationController上推送ViewController。 但是,該應用程序與SIGABRT或EXC_BAD_ACCESS崩潰。 這是因爲我在AppDelegate.m中插入了帶有NavigationController的代碼 有沒有想法?按下帶導航控制器的按鈕時iOS應用程序崩潰

AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch. 
UIViewController *vc; 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
    vc = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; 
} else { 
    vc = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; 
} 

UINavigationController* navController = 
[[UINavigationController alloc] initWithRootViewController:vc]; 
navController.navigationBarHidden = true; 
[self.window addSubview:navController.view]; 

[self.window makeKeyAndVisible]; 
return YES; 
} 

ViewController.m:

- (IBAction)SettingsPressed:(id)sender { 
NSLog(@"SettingsPressed!"); 
} 

要明確:我的本意是隻改變視圖按下SettingsButton並具有返回 - 當按鈕返回。但該應用程序已經崩潰與空事件處理程序。當SIGABRT發生

ERRORMESSAGE

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString SettingsPressed:]: unrecognized selector sent to instance 0x7a06fc0' 
+0

你可以把線路崩潰嗎? – 2012-03-02 12:42:58

+0

我剛剛從控制檯添加了發生的errormessage。希望這就是你的意思。 – Marv 2012-03-02 13:03:09

+0

好吧,我越來越近了,我可以看到一段代碼,你打電話給SettingsPressed – 2012-03-02 13:04:09

回答

0

當然你將消息發送到了錯誤的對象,在你的代碼運行查找,看是否要發送直接SettingsPressed到NSString的消息,並檢查你是否在界面構建器中建立了正確的連接。您也可以發送調試程序po addressOfCrashingInstance以接收更多信息。

+0

我真的不知道如何調試。在控制檯中,當我輸入'po addressOfCrashingInstance'我收到'錯誤:使用未聲明的標識符'addressOfCrashingInstance' 錯誤:1錯誤解析表達式' 接口生成器中的連接應該沒問題。 – Marv 2012-03-02 18:04:21

+0

我的意思是將addressOfCrashingInstance替換爲調試器中顯示的實例地址,如po 0x7a06fc0 – Andrea 2012-03-02 21:30:57

+0

好的,下次我會這樣做。謝謝 – Marv 2012-03-02 21:58:00

1

我剛剛解決了。 我在AppDelegate.h插入一個屬性,合成它在AppDelegate.m,然後將其編輯爲以下內容:這麼大的影響

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch. 
UIViewController *vc; 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
    vc = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; 
} else { 
    vc = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; 
} 

_navController = [[UINavigationController alloc] initWithRootViewController:vc]; 
_navController.navigationBarHidden = true; 
[self.window addSubview:_navController.view]; 
[self.window makeKeyAndVisible]; 
return YES; 
} 

這樣的小錯誤。 但是不知道爲什麼我的代碼會導致錯誤。也許任何人都可以簽字?

相關問題