xcode global variables
how to get xcode variables result from one view controller to another view controller,
actually in one view controller i called web services to get userID which is declare as NSString, and in another view controller开发者_开发技巧 i want to display the userID which is retrieve from previous view controller, so how this can be done
thanks
You're a bit confused, starting with your terminology:
- The language is Objective-C.
- The framework is Cocoa (Mac) or Cocoa Touch (iPhone).
- The IDE is Xcode.
What you really want to do is have a common data model in your application, independent of the views in your application. See any of the copious documentation on how Cocoa and Cocoa Touch implement the Model-View-Controller pattern to understand how to do this.
I think the most simple answer to your solution is to just create an instance variable in the View Controller you wish to pass the variable value to then in your initial view controller, initialize the view controller and then set the instance variable for that controller before pushing it onto the navigation controller stack. for eg.
- (void)buttonPressed:(id)sender
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detailViewController.userID = @"User's ID";
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
Now in your DetailViewController implementation you can access the user's ID by going self.userID
精彩评论