简体   繁体   中英

Issue with custom navigation controller iOS 6

I have created a custom navigation controller in appDelegate :

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

poemsView  = [[[PoemsViewController alloc]initWithNibName:@"PoemsViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:poemsView] autorelease];
self.navigationController.navigationBarHidden = YES;


self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.navigationController;

[self.window makeKeyAndVisible];

so the problem is I need my app lunches from viewController , but if I set my viewController as rootviewController , my navigation controller does not push navigation and vice versa , if set my navigation controller as a root , app does not load from menus or main view controller .

Why you Creating Poemsview as rootviewcontroller of Navigation Controller ?

if You Want To Load ViewController First Then use the following Code.

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];

poemsView  = [[[PoemsViewController alloc]initWithNibName:@"PoemsViewController" bundle:nil] autorelease];

self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.viewController] autorelease];

self.navigationController.navigationBarHidden = YES;



self.window.rootViewController = self.navigationController;

[self.window makeKeyAndVisible];

You Can Create Another Navigation Controller as a Sub-class of Viewcontroller.

In your Poem Button Action Add The Following :

// Create a regular view controller.
PoemViewController *modalViewController = [[[PoemViewController alloc] initWithNibName:@"PoemViewController" bundle:nil] autorelease];

// Create a navigation controller containing the view controller.
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:modalViewController];

// Present the navigation controller as a modal view controller on top of an existing navigation controller
[self presentModalViewController:secondNavigationController animated:YES];

Now You can be able push To detail View from Your tableview DidselectRowAtindexpath .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM