所以我正在构建一个应用程序,我有一个主要视图,其中大部分操作发生。我希望它是这样的,当用户向上滑动时,屏幕底部会出现一个表格视图,在该视图中,他们可以选择某一行并返回主视图。
我以为我做得不对,但当我向上滑动时收到错误消息:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '- [UIViewController _loadViewFromNibNamed:bundle:] loaded the
"SFFavoritesViewController" nib but the view outlet was not set.'
然后我设置了视图插座,我收到了以下错误消息:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
reason: 'A view can only be associated with at most one view controller at a time!
View <UITableView: 0xb385c00; frame = (0 0; 320 568); clipsToBounds = YES;
opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0xa38c0c0>; layer =
<CALayer: 0xa4cf480>; contentOffset: {0, 0}> is associated with
<UITableViewController: 0xa38cde0>. Clear this association before associating
this view with <SFFavoritesViewController: 0xa3819f0>.'
所以我只是想弄错,或者是我试图做的甚至是什么,或者是什么?我有点困惑。
修改
这是我加载/呈现它的地方。此方法位于SFViewController中,它是主视图控制器。
- (void)swipedUp {
SFFavoritesViewController *favoritesViewController = [[SFFavoritesViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:favoritesViewController];
[self presentViewController:navController animated:YES completion:nil];
}
答案 0 :(得分:2)
您正在分配初始化您的favouritesViewController,但您没有将视图与其关联 - 这就是您收到未设置视图插座的消息的原因。要为视图加载XIB文件,您可以使用 -
SFFavoritesViewController *favoritesViewController = [[SFFavoritesViewController alloc]initWithNibName:@"favouritesView" bundle:nil];
确保已将“文件所有者”的自定义类设置为IB中的SFFavoritesViewController
另外,以模态方式呈现导航控制器似乎很不寻常 - 我原本以为你会直接呈现SFFavoritesViewController
[self presentViewController:favoritesViewController animated:YES completion:nil];