UIViewControllerHierarchyInconsistency错误 - 应用程序不断崩溃

时间:2012-10-22 14:07:49

标签: objective-c xcode

  

2012-04-18 12:58:07.108 MYiPad [12574:c07]由于终止应用程序   未捕获的异常UIViewControllerHierarchyInconsistency,原因:A   视图最多只能与a处的一个视图控制器关联   时间!查看< UITableView:0xb0eae00; frame =(0 0; 320 960);   clipsToBounds = YES; autoresize = W + H; gestureRecognizers =< NSArray的:   0xac460e0取代; layer =< CALayer:0xac46830&gt ;; contentOffset:{ - 0,-20}>   与<相关联RootViewController:0xac20f20>。清楚这一点   关联此视图与之前的关联。

     

第一次抛出调用堆栈:(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:终止调用throw a   例外

* - (void)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;

} *

我一直收到这个错误,我无法弄清楚我做错了什么。我的nib文件,我正在使用拆分视图控制器。处理菜单的根视图控制器和处理细节的详细视图控制器(显然)。当我注释掉这一行 [myEngine setTableview:self.tableView]; 应用程序将运行,我不会得到UIViewControllerHierarchyInconsistency错误但是菜单不会加载,因为我正在评论它。有人请帮助我,我需要这个,我的生活取决于它。再次感谢。

EDITED ----

* - (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[Engine 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;

} - (void)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];

} *

我听到你在说什么,但我认为我做的事情非常简单,或者是一些简单的调整。上面的代码来自我的app delegate。

我查看了这个网站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/

我认为这可能与我正在做的事情有关。我可能错了,如果我,请告诉我。

1 个答案:

答案 0 :(得分: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