Iphone-pushViewController is not working in XCode 4.2
Question
I am working on an app which has been created in Xcode 3.2.5. My app is working as expected in XCode 3.2.5 but because of some memory issues now I am using Xcode 4.2.
Xcode 4.2 offers a tool to convert existing code into ARC [which stands for Automatic Reference Counting.] enabled code . Select Edit -> Refactor... -> Convert to Objective-C ARC…worked for me.
In my code I am using navigationController to switch between views on UIbutton click. UIButton created programmatically. I am using following code to push view controller on button_click:
-(void) button_click:(id)sender{
NSLog(@"button_clicked.....");
SecondView *sv = [[SecondView alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:sv animated:NO];
}
On button_click console showing message button_clicked….. but pushViewcontroller not pushing SecondView.
pushViewController is working in XCode 3.2.5 but in XCode 4.2 button click is working but navigationController's pushviewController is not working.
how can i fix it?
Any help would be greatly appreciated.
Thank you in advance!
Solution
Did you try putting the RootViewController into a navigation controller on the MainWindow.xib?
Addition to my answer:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
// create the MyView controller instance:
MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
// set the title that appears in the navigation bar:
[controller.navigationItem setTitle:@"Main View"];
// create the Navigation Controller instance:
UINavigationController *newnav = [[UINavigationController alloc] initWithRootViewController:controller];
// set the navController property:
[self setNavController:newnav];
// release both controllers:
[newnav release];
[controller release];
// add the Navigation Controller's view to the window:
[window addSubview:[navController view]];
return YES;
}
or
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
Handling NavigationControllers is explained in detail here