IPhone Dev - I need the identifier from the last view I visited

I need to create a code to track which identifier I use from the order view, but now I can’t get it to work, can someone paste the code for me?

I need a TagID from view1 β†’ view2, so when I come to view2, I can get information about it and send it to users on the screen.

I need a little help here: 0)

0
source share
1 answer

I think that you are saying here that you are switching from one UIView to another in your application, and you need to somehow "pass" the variable from view1 to view2.

This is a common example of using iPhone with application design, and there are several approaches. Here's what I think is the easiest approach, and it will work for any object in general (integers, NSManagedObjects, whatever): create an iVar in the second view and set it to the value you want to track before making it visible.

Define this in your ViewTwoController with something like:

ViewTwoController.h: ==================== @interface ViewTwoController : UIViewController { NSUInteger *tagID; } @property (nonatomic, assign) NSUInteger *tagID; @end ViewTwoController.m =================== @synthesize tagID; 

So, at this point, your ViewTwoController has an iVar for tagID. Now all we need to do from View One is create a ViewTwoController, assign a tagID value, and then display this second view. This can be done in the button selector or from the UITableView line as such:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ViewTwoController *viewTwoController = [[ViewTwoController alloc] init]; viewTwoController.tagID = self.tagID; // !! Here is where you "pass" the value [self.navigationController pushViewController:viewTwoController animated:YES]; } 

What the above code does: (1) create a new ViewTwoController, (2) assign the tagID iIDar tagID value to the ViewTwoController, then (3) present two view to the user. Thus, in your ViewTwoController code, you can access tagID with self.tagID .

Hope this helps!

+1
source

All Articles