I have an app which uses a UITabBarController which contains 4 different navigation controllers. For example,
1) “Feed” view Navigation Controller
2) “Most Popular” view Navigation Controller
3) “News” view Navigation Controller
4) “More” view Navigation Controller
For each of the navigation controller, there might be a few common viewcontrollers that will need to be pushed onto their existing stack. For example, if I click on the user profile pic displayed in both ‘Feed’ and ‘News’ viewcontrollers, they should push the userProfile viewcontroller onto their stacks.
Currently I see myself repeating codes like this across different navigation controllers:
UserProfileViewController *user = [[UserProfileViewController alloc]init];
user.propertyA = XXX;
user.propertyB = YYY;
[self.navigationController pushViewController:user animated:YES];
I am afraid this will become too repetitive and confusing especially you have multiple navigation controllers in place.
My question will be how to re-factor the code such that all nav controllers will not need to repeat the code everytime it needs to load a common view controller.
Thanks in advance
Make a static selector on the UserProfileViewController, like this:
and in its implementation put those four lines of code from your question, but make sure you autorelease the created UserProfileViewController.