muttley91
muttley91

Reputation: 12684

How to Properly Switch Between Views

I'm making an iOS app (first actual app that isn't Hello World), and it will have 2 screens. I asked on here before how to make one screen (or View Controller) open another, and this is what I figured out to use:

[self presentViewController:[[self storyboard] instantiateViewControllerWithIdentifier:@"statView"] animated:YES completion:nil];

It works. However, it gives me the following message when this runs:

Unknown class statView in Interface Builder file. (Note: this doesn't stop me from using the app, it just seems to be a warning.

This leads me to believe I'm doing something wrong. Also, it seems I'm instantiating this new view controller, but never getting rid of it. So when I go back and forth, I imagine I might be leaving these View Controllers instantiated as new every time?

So my question is:

  1. If there is a better way to switch between these windows, how can it be done?

  2. If this is correct, why the error message?

Upvotes: 0

Views: 148

Answers (1)

Vincent
Vincent

Reputation: 4409

The most easy way is unsing the Storyboard. Add a button and link it to the second view.

You can use a Segue to parse data:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if([[segue identifier] isEqualToString:@"SEGUENAME"]) {
        SecondViewController *secondViewController = [segue destinationViewController];
        secondViewController.parameter = parameter;    // Parse a value
     }
}

Upvotes: 2

Related Questions