gpt4 book ai didi

ios - UIViewControllerHierarchy不一致

转载 作者:技术小花猫 更新时间:2023-10-29 10:08:32 26 4
gpt4 key购买 nike

我正在尝试构建我的应用程序,有一次我推送了一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com