當我運行此下面的代碼它給上面的錯誤程序接收到的信號「EXC_BAD_ACCESS」
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window makeKeyAndVisible];
self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
self.firstViewController=[[FirstViewController alloc]initWithNibName:nil bundle:nil];
UINavigationController *localNavigationController=[[UINavigationController alloc]initWithRootViewController:self.viewController];
self.navigationController=localNavigationController;
[localNavigationController release];
UINavigationController *localFistNavigationController=[[UINavigationController alloc]initWithRootViewController:self.firstViewController];
self.firstNavigationController=localFistNavigationController;
[localNavigationController release];
NSArray *twoBars=[[NSArray alloc]initWithObjects:self.navigationController,self.firstNavigationController, nil];
UITabBarController *localTAbBarController =[[UITabBarController alloc]init];
[localTAbBarController setViewControllers:twoBars];
self.tabBarController=localTAbBarController;
[localTAbBarController release];
[self.window addSubview:self.tabBarController.view];
return YES;
}
如果我運行下面的代碼運行狀況良好
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window makeKeyAndVisible];
self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
self.firstViewController = [[FirstViewController alloc] initWithNibName:nil bundle:nil];
self.navigationController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
self.firstNavigationController=[[UINavigationController alloc]initWithRootViewController:self.firstViewController];
NSArray *twoBars=[[NSArray alloc]initWithObjects:self.navigationController,self.firstNavigationController, nil];
self.tabBarController=[[UITabBarController alloc]init];
[self.tabBarController setViewControllers:twoBars];
[self.window addSubview:self.tabBarController.view];
return YES;
我不明白的是這之間的區別。在第一個我剛剛創建的本地變量&分配給那些屬性。在稍後的一箇中直接使用這些屬性。 爲什麼它是給無差錯程序收到信號「EXC_BAD_ACCESS」
化妝的NSLog您的視圖控制器的viewDidLoad中,然後檢查您是否能夠訪問此視圖 – Rajneesh071
爲了EXC_BAD_ACCESS崩潰更容易調試進入斷點導航器,並添加一個異常斷點(使用默認設置)。 也在Scheme Editor中檢查「啓用殭屍對象」和「日誌例外」框。這將幫助您瞭解發生碰撞的位置。 – krafter
使用ARC(自動引用計數)。沒有理由不這樣做。 –