使用 UINavigationItem 而不是 UINavigationController 的 PushViewController
我已经实现了一个方法 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然你不能这样做
[[self navItem]pushViewController:dvControllerAnimated:YES];
因为UINavigationItem
不是UINavigationController
。您必须使用
[[self navigationController] PushViewController:dvControllerAnimated:YES];
代替。除此之外,我不明白你在问什么。Obviously you can't do
[[self navItem]pushViewController:dvController animated:YES];
because aUINavigationItem
isn't aUINavigationController
.You have to use
[[self navigationController] pushViewController:dvController animated:YES];
instead. Beyond that, I don't get what you're asking.您需要将视图(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).