Question

So I'm building an app and I have a main view where most of the action happens. I want it to be so that when the user swipes up, a table view comes up from the bottom of the screen in which they can select a certain row and return back to the main view.

I thought I did it correctly but when I swiped up I received an error message:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: '- [UIViewController _loadViewFromNibNamed:bundle:] loaded the
"SFFavoritesViewController" nib but the view outlet was not set.'

So then I set the view outlet and I received this error message:

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

So am I just going about this wrong, or is what I'm trying to do even possible, or what? I'm a little confused.

Edit:

This is where I load/present it. This method is in SFViewController, which is the main view controller.

- (void)swipedUp {

    SFFavoritesViewController *favoritesViewController = [[SFFavoritesViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:favoritesViewController];
    [self presentViewController:navController animated:YES completion:nil];
}
Was it helpful?

Solution

You are allocating an initialising your favouritesViewController, but you aren't associating a view with it - which is why you get the message that the view outlet wasn't set. To load the XIB file for your view you would use -

SFFavoritesViewController *favoritesViewController = [[SFFavoritesViewController alloc]initWithNibName:@"favouritesView" bundle:nil];

Make sure you have set the Custom Class for 'Files owner' to SFFavoritesViewController in IB

Also, it seems unusual to present a navigation controller modally - I would have thought you would have just presented the SFFavoritesViewController directly

[self presentViewController:favoritesViewController animated:YES completion:nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top