我在AppDelegate.h文件下面的代碼:應用程序崩潰加載視圖控制器
@class mainViewController;
@class AboutViewController;
@interface iSearchAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
mainViewController *viewController;
AboutViewController *aboutController;
UINavigationController *nav;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet mainViewController *viewController;
@property (nonatomic, retain) IBOutlet AboutViewController *aboutController;
@property (nonatomic, retain) IBOutlet UINavigationController *nav;
[...IBActions declared here...]
@end
然後,在我的.m文件:
@implementation iSearchAppDelegate
@synthesize window;
@synthesize viewController, aboutController, settingsData, nav, engines;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:nav.view];
[window addSubview:aboutController.view];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
-(IBAction)switchToHome{
[window bringSubviewToFront:viewController.view];
}
-(IBAction)switchToSettings{
[window bringSubviewToFront:nav.view];
}
-(IBAction)switchToAbout{
[window bringSubviewToFront:aboutController.view];
}
- (void)dealloc {
[viewController release];
[aboutController release];
[nav release];
[window release];
[super dealloc];
}
@end
不知怎的,當我運行的應用程序,主視圖呈現良好...但是,當我嘗試執行切換視圖的操作時,應用程序會崩潰並顯示EXC_BAD_ACCESS。
所以,我認爲這與內存管理有關,但我不太確定。
感謝您提前提供任何幫助。
鏈接的代碼截圖是在這裏:link ...
解決:我通過取出IBActions,使他們進入正規的方法解決了該問題......顯然,XCode的不喜歡它,當你把IBActions放在AppDelegate中。
謝謝,我解決了這個問題 - 顯然,這是導致應用程序崩潰的IBActions,我猜你不能通過應用程序委託來執行IBActions。 – element119 2010-06-13 20:26:29