UINavigationController not working
I was using a UITabBar
for my application but (for my own reasons) I had to remove it. Now none of my UINavigationControllers
work. Where that manifests itself most is when I call: [self.navigationController pushViewController:myViewController animated:YES];
That code now does nothing because I have no UINa开发者_如何学PythonvigationController
and I don't know how to make one that will work.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Initialize window components
UINavigationController *myNavController = [[UINavigationController alloc] init];
[self setNavController: myNavController];
[myNavController release];
FirstViewController *cViewController = [[FirstViewController alloc] init];
[self setMyFirstView: cViewController];
[cViewController release];
[self.window addSubview: [self navController].view];
[[self navController] pushViewController: myFirstView animated:YES];
[self.window makeKeyAndVisible];
return YES;
}
This should do the trick.
By the way, you should declare the following for that in the delegate.h:
@property (nonatomic, retain) UINavigationController *navController;
@property (nonatomic, retain) IBOutlet CatchengoViewController *viewController;
@property (nonatomic, retain) UIViewController *myFirstView;
Create a navigation controller and add it to the view as a subview or initialise it with your main view controller. It can be done from IB too. Google for navigation based app sample code for more info.
精彩评论