2012-10-22 39 views
0

2012-04-18 12:58:07.108 MYiPad [12574:C07]終止應用程序由於 未捕獲的異常UIViewControllerHierarchyInconsistency,原因:甲 視圖只能與最多一個視圖相關聯控制器在 時間!查看< UITableView:0xb0eae00; frame =(0 0; 320 960); clipsToBounds = YES; autoresize = W + H; gestureRecognizers = < NSArray: 0xac460e0>;層= < CALayer:0xac46830>; contentOffset:{-0,-20}> 與< RootViewController:0xac20f20>相關聯。在關聯此視圖之前清除此關聯 。UIViewControllerHierarchyInconsistency錯誤 - 應用保持崩潰

第一擲調用堆棧:(0x1b57012 0x153ce7e 0x1b56deb 0x4cf309 0x5665ac 0x562a90 0x6b0232 0x4e257 0x21e3f 0x184a8c 0x19c417d 0x1836d2 0xc4c2 0x1aae59 0x1a8f22 0x1aa16a 0x1a8edd 0x1a9055 0xf6338 0x1e64a81 0x1e63d33 0x1ea1e3a 0x1af98fd 0x1ea24bc 0x1ea2435 0x1d8c3a0 0x1adaf3f 0x1ada96f 0x1afd734 0x1afcf44 0x1afce1b 0x24917e3 0x2491668 0x48165c 0x2c8d 0x2bc5爲0x1)的libC++ abi.dylib:終止叫做拋出異常

* - (無效)viewDidLoad中{

[self.tableView initWithFrame:self.tableView.frame style:UITableViewStyleGrouped]; 
self.tableView.contentInset = UIEdgeInsetsMake(20.0,0.0,0.0,0.0); 
self.appDelegate = (FCDBiPadAppDelegate *)[[UIApplication sharedApplication] delegate]; 
[self.tableView setBackgroundView:nil]; 
[self.tableView setBackgroundView:[[[UIView alloc] init] autorelease]]; 
[self.tableView setBackgroundColor:[UIColor colorWithRed:217 green:220 blue:225 alpha:0.9]]; 
unsigned int b; 
NSScanner *scanner = [[NSScanner alloc] initWithString:[[[Engine sharedInstance] properties] objectForKey:@"NAVBAR_COL"]]; 
[scanner scanHexInt:&b]; 
[scanner release]; 
self.navigationController.navigationBar.tintColor=[UIColor blackColor]; 
//self.navigationController.navigationBar.tintColor=UIColorFromRGB(b); 
views = [[NSMutableArray alloc] init]; 
NSMutableArray *innerArray =[[NSMutableArray alloc] init]; 
[innerArray addObject:@"Login"]; 

txnlist = [[NSMutableArray alloc] init]; 
[txnlist addObject:@"RRLGN00"]; 
NSMutableDictionary *menu1Dict = [NSMutableDictionary dictionaryWithObject:innerArray forKey:@"MENU"]; 
[menu1Dict setObject:txnlist forKey:@"MENUKEY"]; 
[views addObject:menu1Dict]; 
Engine *myEngine = [Engine sharedInstance]; 

**[myEngine setTableview:self.tableView];** 
[myEngine settableData:self.views]; 


[super viewDidLoad]; 
self.clearsSelectionOnViewWillAppear = NO; 
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0); 
self.navigationItem.hidesBackButton = TRUE; 

} *

我不斷收到這個錯誤,我無法弄清楚它是什麼,我做錯了。我的筆尖文件,我正在使用分割視圖控制器。處理菜單的根視圖控制器和處理細節的明細視圖控制器(顯然)。當我註釋掉這一行[myEngine setTableview:self.tableView]; 該應用程序將運行,我不會得到UIViewControllerHierarchyInconsistency錯誤,但該菜單不會加載,因爲我評論它。有人請幫助我,我需要這個儘快,我的生活取決於它。再次感謝。

EDITED ----

* - (BOOL)應用:(UIApplication的*)應用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions {
[[發動機sharedInstance] setmenu_curr:@ 「RRLGN00」]; [[Engine sharedInstance] setProperties:[[NSMutableDictionary alloc] initWithDictionary:[NSMutableDictionary dictionaryWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@「app.plist」]]]];

[[[Engine sharedInstance] properties] setObject:NSLocalizedString(@"FCDB_LANGID", nil) forKey:@"idLang"]; 

[[Engine sharedInstance] setUrl:[[[[Engine sharedInstance] properties] objectForKey:@"ENTITY_URL"] objectAtIndex:0]]; 
splashController = [[SplashViewController alloc]initWithNibName:@"SplashViewController" bundle:[NSBundle mainBundle]]; 
splashController.delegate=self; 
[self.window addSubview:splashController.view]; 
[self.window makeKeyAndVisible]; 

return YES; 

} - (無效)hideSplash { [splashController.view removeFromSuperview];

self.splitViewController =[[UISplitViewController alloc]init]; 
self.rootViewController=[[RootViewController alloc]init]; 
self.detailViewController=[[DetailViewController alloc]init]; 
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController]; 
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController]; 
//detailNav.navigationBarHidden=YES; 
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailViewController,nil]; 
self.splitViewController.delegate=detailViewController; 
[window addSubview:self.splitViewController.view]; 
[self.window makeKeyAndVisible]; 

} *

我聽到你在說什麼,但我想我做的事情很簡單的錯誤,或者一些簡單的調整。上面的代碼來自我的應用程序委託。

我檢查這個網站了http://www.iriphon.com/2012/03/31/uncaught-exception-uiviewcontrollerhierarchyinconsistency-reason-child-view-controller-should-have-parent-view-controller-but-actual-parent-is-or-apples-new-uiviewcontroller-hierarc/

,我認爲這可能與什麼IM做的事情。我可能是錯的,如果我是,請告訴我。

+0

不知道如果我正確interpresting,但我有兩個視圖控制器指向行中的相同視圖.. self.splitViewController.viewControllers = [NSArray arrayWithObjects:rootNav,detailViewController,nil]; self.splitViewController.delegate = detailViewController; [window addSubview:self.splitViewController.view]; – Sonic

回答

0

錯誤告訴你你需要知道的一切。視圖只能屬於它最初創建的視圖控制器。

我猜EngineUIViewController的一個子類,要麼或Engine包含一個視圖控制器。在-setTableview:方法中,我猜測你以某種方式將表視圖添加到該視圖控制器。

注意:如果你真的需要這個表視圖是Engine的一部分,你需要完全斷絕與RootViewController的連接。在實踐中,我從來沒有見過這樣做。

P.S. [super viewDidLoad]應該是您從-viewDidLoad撥打電話的第一件事。


評論爲您更新的代碼

注:我不認爲這將解決您的問題,但它的設置窗口的正確方法。

請勿使用[self.window addSubview:splashController.view][window addSubview:self.splitViewController.view]。相反,它應該是self.window. rootViewController = splashControllerself.window.rootViewController = self.splitViewController

+0

我編輯了上面的帖子,並添加了一些更多的代碼,請看看,讓我知道你的想法。謝謝。 – Sonic

+0

不知道如果我正確interpresting,但我有兩個視圖控制器指向行中相同的視圖.. self.splitViewController.viewControllers = [NSArray arrayWithObjects:rootNav,detailViewController,零]; self.splitViewController.delegate = detailViewController; [window addSubview:self.splitViewController.view]; – Sonic

+0

@Sonic我不確定你想指出什麼。 'self.splitViewController.viewControllers = [NSArray arrayWithObjects:rootNav,detailViewController,nil]'是一個指向子視圖控制器(合法)的控制器。 'self.splitViewController.delegate = detailViewController'正在設置一個委託(合法)。 '[window addSubview:self.splitViewController.view]'是我已經評論過的代碼。 –