UIViewControllerHierarchyInconsistency [英] UIViewControllerHierarchyInconsistency

查看:186
本文介绍了UIViewControllerHierarchyInconsistency的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建我的应用程序,有一次我推了一个UIViewController然后我得到了这个错误。我不确定为什么。

I am trying to build my app and at one point I push a UIViewController and then I get this error. I am not exactly sure why.


'UIViewControllerHierarchyInconsistency',原因:'视图一次最多只能与
关联一个视图控制器!视图>与...相关联。在将此视图与
相关联之前清除此关联。'

'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View > is associated with . Clear this association before associating this view with .'



PageViewController *viewController;

viewController = [[PageViewController alloc] initWithManagedObjectContext:managedObjectContext];
dataSource = [[PagesDataSource alloc] initWithManagedObjectContext:managedObjectContext];

PVPage *selectedPage = [[dataSource pages] objectAtIndex:itemIndex];
[viewController setRepresentedPage:selectedPage];

PageFlipperAppDelegate *appDelegate = (PageFlipperAppDelegate *)[[UIApplication sharedApplication] delegate];
[(UINavigationController *)[[appDelegate window] rootViewController] setToolbarHidden:YES animated:YES];
[(UINavigationController *)[[appDelegate window] rootViewController] pushViewController:viewController animated:YES];

在我的pageViewController中.................. 。

In my pageViewController...................

- (id)initWithManagedObjectContext:(NSManagedObjectContext *)initManagedObjectContext
{
    if ((self = [super initWithNibName:@"PageView" bundle:nil]))
    {
        [self setManagedObjectContext:initManagedObjectContext];
        dataSource = [[PagesDataSource alloc] initWithManagedObjectContext:[self managedObjectContext]];
    }
    return self;
}


推荐答案

我出现了同样的错误当我想要一个设置滚动视图出现在一个弹出框中。

I had the same error arise when I wanted a settings scroll view to appear in a popover.

这是我的原始代码,其中包含有关我改变解决方法的评论:

Here is my original code with comments about what I changed to resolve it:

SettingsViewController *settingsViewController;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];    
settingsViewController = [storyboard instantiateViewControllerWithIdentifier:@"Settings"];

CGRect contentRect = CGRectMake(10, 10, 320, 700);

// This entire object got deleted in the fixed version
UIViewController *popoverContent = [[UIViewController alloc] init];
popoverContent.view = settingsViewController.view;
popoverContent.contentSizeForViewInPopover = contentRect.size;

// Instead of popoverContent I just put the settingsViewController in directly.
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];

[popoverController presentPopoverFromRect:[sender frame]
                                   inView:(UIButton*)sender
                 permittedArrowDirections:UIPopoverArrowDirectionLeft
                                 animated:YES];

popoverContent.view = settingsViewController.view 是导致崩溃的原因(没有它我的popover当然是空的)。从UIViewControllerHierarchyInconsistency错误的角度来看,我不应该重新分配它然后将它添加到另一个视图控制器。

The line popoverContent.view = settingsViewController.view is what was causing the crash (without it my popover was empty of course). From the point of view of the UIViewControllerHierarchyInconsistency error it makes sense that I shouldn't have been reassigning it and then adding it to another view controller.

在你的情况下我' d猜测pushViewController或代码中的其他地方发生了类似的事情。可能就是这样吗?

In your case I'd guess something similar is happening in pushViewController or elsewhere in your code. Could that be the case at all?

这篇关于UIViewControllerHierarchyInconsistency的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆