简体   繁体   中英

UInavigation Controller not working from switching view controller to tableviewcontroller

I'm trying to implement UInavigation controller to switch views from view controller to table view controller.Here is my code.

-(IBAction)product:(id)sender
{
Products *second=[[Products alloc]init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:second];

nav.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;

[self.navigationController pushViewController:second animated:YES];

}

But i'm not getting it..Am i missing anything..

First of all, make sure "Products" is a subclass of UIViewController. If it's a view controller subclass with a .XIB file, instantiate it using "initWithNibName", not alloc & init:

Products *second = [[Products alloc] initWithNibName:"YourXibFileName.xib" bundle:[NSBundle mainBundle]];

The second issue here is that you instantiate a UINavigationController for no reason - remove this line and just stay with self.navigationController.

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