如何解决多个NavigationController出错
| 我正在制作一个具有2个导航控制器的应用程序。一个有一个tableView,当在单元格中轻按时,我想加载另一个viewController,但是我总是会遇到此错误:fifthvieController may no respond to -navigationController2
这是代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *letraSeleccionada = [lista objectAtIndex:indexPath.row];
FourthViewController *fourth = [[FourthViewController alloc]initWithNibName:@\"FourthViewController\" bundle:nil];
fourth.letraSeleccionada = letraSeleccionada;
[[self navigationController2] pushViewController:fourth animated:YES]; //here
[fourth release];
fourth = nil;
}
我已经更改了代码,现在可以使用了,但是我不明白为什么它不起作用。这里是新代码:
PruebaPushAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
[delegate.navigationController2 pushViewController:fourth animated:YES];
//[[self navigationController2] pushViewController:fourth animated:YES];
解决方法
由于您使用了两个导航控制器,因此我猜想这是一个带有两个选项卡和一个导航控件的选项卡栏应用程序?而您为此使用了界面生成器?
如果是这种情况,则无需声明导航控制器,因为视图控制器已经作为第一个视图控制器位于它们内部。
试一试:
[[self navigationController] pushViewController:第四个动画:是];
, 您是否已将navigationController2声明为属性?看起来它只是一个变量。如果使用属性,则只能将\“ self \”与它一起使用。
@property (nonatomic,retain) UINavigationController navigationController2;// in .h
@synthesize navigationController2; //in .m
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。