Question

Wondering how I can set properties of view controllers that are already on the NavigationController's stack

My situation:

I want to set up an image uploading flow like this

(Navigation Stack) RootViewController -> TakePictureViewController -> EditPictureViewController -> UploadPictureViewController

When user confirms the upload from the UploadPictureViewController, rather than start to upload, I want to set an NSDictionary property on RootViewController which contains the upload query, then pop the navigation stack back down to the RootViewController and have it handle initiating and status reporting of the query.

Here's my code in the uploadpictureviewcontroller, currently, the code does pop to the right view controller, but the uploadPackage property is still nil, also I have tried to -setUploadPackage

RootViewController *rvc = (RootViewController *)[self.navigationController.viewControllers objectAtIndex:0];

rvc.uploadPackage = uploadPackage;

[self.navigationController popToViewController:rvc animated:YES]; 

All help appreciated, thanks.

Was it helpful?

Solution

try using [self.navigationController popToRootViewControllerAnimated:YES]. That should do it.

EDIT:

If you have only one instance of RootViewController, then you can set it up as a singleton and therefore you can access it from any other controller (just like the appDelegate). To do so you need to add the following to your RootViewController.m under synthesize...; :

static RootViewController *rootViewController;

+(id)sharedRootController {
    return rootViewController;
}

inside your init method for RootViewController add the following line:

rootViewController = self;

now back to your UploadPictureViewController you can set the uploadPackage like this:

RootViewController *rvc = [RootViewController sharedRootController];
rvc.uploadPackage = uploadPackage;

Please note that you should NOT use the singleton method if there is to be more than one instance of RootViewController.

hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top