使用 UINavigationItem 而不是 UINavigationController 的 PushViewController

发布于 2024-08-26 15:12:55 字数 1076 浏览 5 评论 0原文

我已经实现了一个方法 didSelectRowAtIndexPath 应该推送另一个视图。我有一个使用 navigationController 正确运行的代码,但在本例中我在视图上使用 navigationItem 。我怎样才能触发视图?感谢

错误日志:

2010-03-25 00:09:52.459 TableArchive[1062:207] trigger
2010-03-25 00:09:52.461 TableArchive[1062:207] *** -[UINavigationItem pushViewController:animated:]: unrecognized selector sent to instance 0x3921ca0
2010-03-25 00:09:52.462 TableArchive[1062:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UINavigationItem pushViewController:animated:]: unrecognized selector sent to instance 0x3921ca0'
2010-03-25 00:09:52.463 TableArchive[1062:207] Stack: (


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 NSLog(@"trigger");

 if(dvController == nil) {
   DetailView *aController =[[DetailView alloc]initWithNibName:@"DetailView" bundle:nil];

   self.dvController = aController;

   [aController release];
 }

 [[self navItem]pushViewController:dvController animated:YES];

 [dvController release];
}

I have implemented a method didSelectRowAtIndexPath that should push another view. I have a code running properly using a navigationController but in this case I am using a navigationItem on a view. How could I trigger a view? Thanx

Error log:

2010-03-25 00:09:52.459 TableArchive[1062:207] trigger
2010-03-25 00:09:52.461 TableArchive[1062:207] *** -[UINavigationItem pushViewController:animated:]: unrecognized selector sent to instance 0x3921ca0
2010-03-25 00:09:52.462 TableArchive[1062:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UINavigationItem pushViewController:animated:]: unrecognized selector sent to instance 0x3921ca0'
2010-03-25 00:09:52.463 TableArchive[1062:207] Stack: (


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 NSLog(@"trigger");

 if(dvController == nil) {
   DetailView *aController =[[DetailView alloc]initWithNibName:@"DetailView" bundle:nil];

   self.dvController = aController;

   [aController release];
 }

 [[self navItem]pushViewController:dvController animated:YES];

 [dvController release];
}

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

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

发布评论

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

评论(2

听,心雨的声音 2024-09-02 15:12:55

显然你不能这样做 [[self navItem]pushViewController:dvControllerAnimated:YES]; 因为 UINavigationItem 不是 UINavigationController

您必须使用 [[self navigationController] PushViewController:dvControllerAnimated:YES]; 代替。除此之外,我不明白你在问什么。

Obviously you can't do [[self navItem]pushViewController:dvController animated:YES]; because a UINavigationItem isn't a UINavigationController.

You have to use [[self navigationController] pushViewController:dvController animated:YES]; instead. Beyond that, I don't get what you're asking.

¢蛋碎的人ぎ生 2024-09-02 15:12:55

您需要将视图(XIB?)中的 UINavigationItem 设置为 UINavigationController 导航项。您可以通过将 IBOutlet 设置为 navItem 来完成此操作,并且在您的代码中只需执行 self.navControllet.navItem = navItem (类似的操作)。

You need to set the UINavigationItem from the view (XIB ?) as your UINavigationController navigation item. You can do this by setting an IBOutlet to the navItem and at your code you just do self.navControllet.navItem = navItem (something like that).

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