How can I display and close the view from the controller?

I just want to display "CreditsView". Therefore, if I press the button, show the type of loans, click ok, the view will disappear.

I have my base controller and my credit view controller, and now I'm trying something like:

- (IBAction)switchToCreditsView:(id)sender {
creditsViewController = [[CreditsViewController alloc] initWithNibName:@"CreditsViewController"];
[self.view addSubview:creditsViewController.view];
//[self presentModalViewController:creditsViewController animated:YES];

}

But if I press the Button button, my application crashed.

+3
source share
2 answers

To go back, you simply call:

- (IBAction)switchToBaseView:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}
+6
source

To go back, do

[self.view removeFromSuperview]; And then free the view if you want. [self release];

+3
source

Source: https://habr.com/ru/post/1717618/


All Articles