也許我一直在尋找這個太久;)我的應用程序有一個NavigationController和幾個ViewControllers。從ViewController的兩個級別downView(mainViewController),從rootViewController加載,我有下面的代碼。在PushViewController到dataViewController後面(例如按下按鈕)後,應用程序崩潰。當使用Init,PushViewController,Release時奇怪的Exc錯誤訪問。這段代碼有什麼問題?
dataViewController加載得很好,但是當輕擊navigationController的後退按鈕時,應用程序會與對象異常一起崩潰。如果我刪除:
[dataViewController release];
該應用程序工作正常。這很奇怪,因爲dataViewController是以相同的方法初始化的。 任何想法?
- (void) locationPage
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"NotifyRemoveMap" object:nil];
MyAppDelegate *app = [[UIApplication sharedApplication] delegate];
UINavigationController *navigation = app.navigationCantroller;
[navigation popToRootViewControllerAnimated:NO];
DataViewController *dataViewController = [[DataViewController alloc] initWithNibName:@"DataView" bundle:nil];
[dataViewController setCategoryId:category];
MyLanguage *lang = app.lang;
Mylocation *location = [lang locationForCategoryId:category];
dataViewController.title = location.name;
NSArray *locationArray = [lang locations];
dataViewController.locations = locationArray;
[navigation pushViewController:dataViewController animated:YES];
[dataViewController release]; // With this removed, app doesn't crash
}
賓果! Lupu1001,你的回答挽救了我的生命! ;) 我喜歡你!!! – Jordan 2010-09-11 04:45:17
很高興我能幫到你。回頭見。 – 2010-09-12 23:56:49