(iOS)
I have a UITableView as a root view (screen 1). when a cell is selected, it pushes a new UIView (screen 2) which contains two buttons. When one of those buttons is pressed, a new UIView is pushed (screen 3).
I would like to pass some key-value pairs from screen 1 to both screen 2 and screen 3. Using the following code I can pass values to screen 2 with no problem, but screen 3 returns zero as the value, regardless of which cell is picked. Any help on why this is happening would be great. (The alternative is to use switch-cases in screen 2 to pass values to screen 3)
Screen 1:
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
NSDictionary *sentItems = [NSDictionary dictionaryWithObjectsAndKeys:indexPath, @"indexPath", nil];
[destination setValue:sentItems forKey:@"sentItems"];
The solution I would think would be easiest is to pass along a
sentItemsor similar dictionary with all the values you could need during initialisation of the second and third views.So if you need values
X,Yfor view 2 andA,B,Cfor view 3 orD,E,Ffor the alternate button view 3, pass a dictionary withX,Y,A,B,C,D,E,Fdefined to view 2 before showing it, then pass the appropriate values to view 3 when you select one of the buttons but before showing that view.That saves looking back in the stack at all. If your first view is actually the root view of the application, you also have the option to define this dictionary in your application delegate class, so it becomes globally accessible via
[[UIApplication sharedApplication]delegate].