self.navigationController is nil after adding subview
Asked Answered
S

5

1

here is my productscontroller.h

ProductListViewController *productListViewController;
ProductGridViewController *productGridViewController;
UIButton *flipIndicatorButton;  

and i am adding list and gridview as a subview like this in my implementation

ProductListViewController *listController = [[ProductListViewController alloc] initWithNibName:@"ProductListView" bundle:nil];
self.productListViewController = listController;
self.productListViewController.CurrentSale = CurrentSale;
[self.view insertSubview:listController.view atIndex:0];

but in when i tried to push detailview controller from ProductListViewController.m like this

ProductDetailViewController *productDetailViewController = [[ProductDetailViewController alloc] init];

productDetailViewController.productIndexPath = indexPath;

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

it just does not work, then i check [self.navigationController] , it was nil, now how to deal with this problem. i am ready to give some more code and detail to make more clear. thanks

September answered 31/12, 2009 at 2:19 Comment(3)
if you're using a navigation controller, why are you inserting a subview instead of pushing views to the controller? also, is the navigation controller nil before you insert the subview as well?Dreamworld
thanks Oren, not its not nil,let me tell how my app structure. TabBarController -NavigationControler --TableViewController ---ProductController(self.navigationControll is not null here) ----ListViewController(self.navigationControll is nil) ----GridViewControler(self.navigationControll is nil) ihope this make picture clear.September
and i am adding flip view button as right button item, that gets added. and i can flip view, but i cant push another view control.September
S
0

i found workaround for this problem. now what i am doing is i am passing ref of parent controller in this case ProductsController and written method to push next view. following this now i am calling parent method to push next view like this [parent pushNextview]; so far it works fine, hope this is good way of doing what i wanted to.

September answered 9/1, 2010 at 21:42 Comment(0)
P
2

Where are you creating the Navigation Controller? At some point (probably in your App Delegate) you have to have something like this:

ProductsController *productsController = // create ProductsController
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:productsController];

And then add the navController's view as a subview to your window.

The other thing is that you appear to be using too many View Controllers for one screen. Apple recommends only one per screen.

Pragmatic answered 31/12, 2009 at 3:26 Comment(2)
thanks bpapa, i am using only one Controller per screen, its just that i cant make view hierarchy in here. i have tabbar, and i have make first tabbar as Navigation in my Mainwindow.xib, and i am creating ProductController in BrandList controller that is my first screen , not app delegate. is this clear.if not let me know how i can make it more clear.September
i follow this example for create subviews(i did same thing with minor change) developer.apple.com/iphone/library/samplecode/TheElements/… , hope this helpsSeptember
D
1

I had the same problem recently! I "poped" ([self.navigationController popViewControllerAnimated:YES]) the viewController in the viewWillAppear: method of the viewcontroller. So I just removed this code and inserted the same code in the viewDidAppear: method and it worked!

Diversify answered 1/8, 2011 at 8:52 Comment(0)
S
0

i found workaround for this problem. now what i am doing is i am passing ref of parent controller in this case ProductsController and written method to push next view. following this now i am calling parent method to push next view like this [parent pushNextview]; so far it works fine, hope this is good way of doing what i wanted to.

September answered 9/1, 2010 at 21:42 Comment(0)
T
0

I ran into a similar issue yesterday:

Tab Bar View - Table View - View

In the table view controller, I wanted to push the "detail view" controller, but [self navigationController] was nil here. The solution was to go to this arrangement:

Tab Bar View - Navigation View - Table View - View

With the additional navigation controller, [self navigationController] now worked in the table view controller.

Transcurrent answered 12/3, 2010 at 14:40 Comment(0)
O
0

I just found out why the navigationController is always nil. Your whole series of views should be contained in a UINavigationController. This means that the first view in your hierarchy will have to be your rootViewController. bpapas code should work.

Olimpia answered 11/6, 2011 at 15:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.