简体   繁体   中英

Passing values when popping a view controller with a UINavigationController

I have a pretty basic question. Assuming I have a UINavigationController set up for my app and I want to pass a value to the previous view when the user hits the "back" button in the UINavigationBar. I know I call popViewController: , but is there a way to pass a value back with it? Assuming there is (which there must be), what's the best way to do this?

Thanks!

What you should do in this case is think about the problem in a different way. You can create a delegate protocol on the view controller you want to pass information back from. This protocol can have any number of methods, at least one of which will look something like viewController:(MyViewController *)theViewController didSelectThisInformation:(NSString *)someInformation . When some action takes place on this view controller, it makes a call to its delegate (which conforms to the protocol you defined) and calls the appropriate method. When pushing this view controller, you would set its delegate property to the object you want to receive that information.

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