简体   繁体   中英

Objective-C Showing a view controller on another view controller programmatically

I've got one problem. I have a viewController1 in which I click a button. When I hit this button, I want it to show another view controller (viewController2) on viewController1 (viewController2 is a little transparent). I'd like to do this programmatically. I tried this but when I hit the button nothing happens:

Notification *newView = [[Notification alloc]initWithNibName:@"Notification" bundle:nil];
[self.navigationController pushViewController:newView animated:YES];

I renamed some variables to make it clearer. Thanks for answers!

EDIT: Maybe I wasn't clear enough, I want viewController2 to be ONTOP of viewController1

Try below:-

 Notification *newView = [[Notification alloc]initWithNibName:@"Notification" bundle:nil];
  [self presentViewController:newView  animated:YES completion:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM