Desmond Desmond - 1 year ago 98
iOS Question

how to pass value when popToRoot

will like to know how do i pass value back to the root view controller when i popToRoot.

introVideoViewController *intro = [introVideoViewController alloc];
intro.fromReset =1;
[self.navigationController popToRootViewControllerAnimated:NO];

Answer Source

With the VC that you want to pop back from, you need to give it a delegate property -

@class MyViewController;

@protocol MyViewControllerDelegate <NSObject>

    -(void)myViewControllerDidDismiss:(MyViewController *)controller withSomeObject:(id)someObject;


@interface MyViewController : UIViewController

@property (nonatomic, assign) id<MyViewControllerDelegate> myViewControllerDelegate;


...and in the root VC you make it conform to that protocol, and implement the dismiss method -

-(void)myViewControllerDidDismiss:(MyViewController *)controller withSomeObject:(id)someObject {

    // now I've got the object from the VC I just popped


Forgot to mention that you need to call myViewControllerDidDismiss:withSomeObject: when you pop the VC.

Edit - Also forgot to mention that you need to set the VC's delegate as your root VC when you create it, or else it'll be trying to call nil when you pop back -

[myViewController setMyViewControllerDelegate:self];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download