Why won't self.navigationController pushViewController work?
Solution 1
In UIBuilder verify that UINavigationController is referenced by the File's owner.
Solution 2
Got it.
I changed the Architecture a little bit.
I made a New UIViewController class with its xib. And coded new UINavigationController.
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationController *navigationController
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];
switch (whichViewController) {
case 1:
viewController = [[xxxx alloc] init];
break;
case 2:
viewController = [[xxx1 alloc] init];
break;
default:
break;
}
[navigationController pushViewController:viewController animated:NO];
[viewController release];
}
And pushing the view in the Switch Statement....
I hope this makes sense ......
Thanks jamihash
Solution 3
So you are adding the tableview to the navigation controller right? This is how:
tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:tableView animated:NO];
The tableview gets added as the rootview to the navigation controller. And then on selecting a row if you wish to push another viewcontroller use the
self.navigationController pushViewController: newViewController animated:YES];
inside the didSelectRowAtIndex method.
NOTE: its UITableViewController *tableView and UINavigationController *navigationController by declaration. So code accordingly for your table.
trio
Updated on June 17, 2020Comments
-
trio almost 4 years
I have a
UIViewController-> UINavigationBar + UITableView
Just a bit more explanation
I made it through UIBuilder..
1: Created a New
UIViewController
with XIB-file
2: UsingUIBuiler
i put aUINavigationController
3: Then i putUITableView
underneath thenavigationBar
so it gave me..A: UIViewController-> UINavigationBar + UITableView
Now i am loading the data in UITableView from a Webservice which is working fine.
I again made a xib with sam config which is
B: UIViewController-> UINavigationBar + UITableView
So now when i try to push view B on view A using below code...it wont at all work...
SelectSiteViewController *siteViewController = [[SelectSiteViewController alloc] initWithNibName:@"SelectSiteViewController" bundle:nil]; [self.navigationController pushViewController:siteViewController animated:YES];
When i checked the
UINavigationController *nav = self.navigation
nav is 0x0 that is i assume NIL.
Can anybody tell me whats wrong in here.. why is it nil...and how can i make it work..
Thanks a Lot....I would really appreciate any help
-
trio over 13 yearsWhen you drop a UINavigationBar from UIBuilder library is it a UINavigationController? It is a UINavigationBar.
-
trio over 13 yearsNo no... I created a new file that is UIViewController with XIB option Selected. For ex: @interface ClasssName : UIViewController <some delegates>{ } So it is a Subclass of UIViewController Now i opened the xib file and drop UINavigationBar Then i drop UITableView onto the xib file which is UIViewController Does this help?
-
jamihash over 13 yearsIts just the bar that appears in the view. You need to either drag and drop UINavigationController in UIBuilder and hook it up to the File's owner's navigation controller. Or you could create in the code.
-
trio over 13 yearsHey can i send you the code ....I tried but couldn't figure out...I would really appreciate any help...Thanks Man
-
jamihash over 13 yearsI would highly recommend you read "Head First Iphone Development". It is really well written and has examples of exactly what you are trying to do. It will save you countless hours and help you get productive fast.