简体   繁体   中英

How to insert a subview with xib?

I'm confused something fierce over having multiple views. I simply want to have a button on my main view that activates a new view, which in turn would have an (x) button which goes back to main view. For the life of me, I can't figure out how to do this with two separate .xib files. How might this be done?

Thanks!

It might be easiest to just use the utility application as a template.

From there, you can see how you would load view controllers and nibs in order to bring up the new view followed by how you would exit it.

I actually solved it by doing it this way:

 NewViewController *new = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
new.delegate = self;
new.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:new animated:YES];
[new release];

You are using a navigation controller, right?

On the IBAction associated with a button tap on the main view, put

NewViewController *newView = ... // [alloc - init your view here if you haven't already]
[self.navigationController pushViewController:newView animated:YES];

And on the button on newView,

[self.navigationController popViewControllerAnimated:YES]

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