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;
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!
Neal l
source share