开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜