ios - UIViewControllerHierarchy不一致

标签 ios

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

'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 中 .....................

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

最佳答案

陷阱场景:如果在同一个 .XIB 文件中有两个 UIViewController,并且 View 导出指向同一个 View ,则在加载 nib 时将引发 UIViewControllerHierarchyInconsistency 异常,例如通过调用其中一个的 .view 属性 View Controller 。

关于ios - UIViewControllerHierarchy不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11877264/

相关文章:

iphone - 滑动删除具有奇怪行为的单元格

ios - UIImageView 在具有不同高度的自定义 UITableViewCell 内自动调整大小

ios - 我正在尝试快速使用自定义委托(delegate),但是当我想调用它的方法时,它没有被调用

ios - 将图像传递给另一个 View Controller

ios - UIBlurEffect 仅在 StatusBar 上(不在 UINavigationBar 上)

iphone - UIView 控件在动画完成之前不绘制

ios - UIButton 在 iOS7 中的 UIPageViewController 中的 ViewController 中没有突出显示

ios - 根据实体之间的关系类型创建 NSFetchedResultsController 部分

ios - 修改字典 [String : [String]]

ios - 为什么我的自定义 UITableViewCell 显示不正确?