添加子视图后 self.navigationController 为零

发布于 2024-08-16 15:02:48 字数 977 浏览 8 评论 0原文

这是我的 productscontroller.h

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

,我在实现中添加列表和 gridview 作为子视图

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

,但是当我尝试从 ProductListViewController.m 推送详细视图控制器时,这样它

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

productDetailViewController.productIndexPath = indexPath;

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

不起作用,然后我检查 [self.navigationController] ,为零, 现在如何处理这个问题。我准备提供更多代码和细节以使其更加清晰。谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

南渊 2024-08-23 15:02:48

您在哪里创建导航控制器?在某些时候(可能在您的应用程序委托中)您必须有这样的东西:

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

然后将 navController 的视图作为子视图添加到您的窗口中。

另一件事是您似乎在一个屏幕上使用了太多视图控制器。 Apple 建议每个屏幕仅使用一个。

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.

倾`听者〃 2024-08-23 15:02:48

我最近也遇到了同样的问题!我在视图控制器的 viewWillAppear: 方法中“弹出”([self.navigationController popViewControllerAnimated:YES])视图控制器。所以我只是删除了这段代码并在 viewDidAppear: 方法中插入了相同的代码,它就起作用了!

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!

离笑几人歌 2024-08-23 15:02:48

我找到了解决这个问题的方法。
现在我正在做的是在本例中传递父控制器的引用 ProductsController 和写入的方法来推送下一个视图。接下来,我现在正在调用父方法来推送下一个视图,如下所示
[父pushNextview];
到目前为止,它运行良好,希望这是做我想做的事情的好方法。

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.

也只是曾经 2024-08-23 15:02:48

我昨天遇到了类似的问题:

Tab Bar View - Table View - View

在表视图控制器中,我想推送“详细视图”控制器,但是 [self navigationController] code> 这里是 nil 。解决方案是采用以下安排:

Tab Bar View - Navigation View - Table View - View

使用附加导航控制器,[self navigationController] 现在可以在表视图中工作控制器。

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.

岛歌少女 2024-08-23 15:02:48

我刚刚发现为什么 navigationController 总是为零。您的整个视图系列应该包含在 UINavigationController 中。这意味着层次结构中的第一个视图必须是 rootViewController。 bpapas 代码应该可以工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文