我正在制作一款有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];
答案 0 :(得分:1)
由于您使用了两个导航控制器,我猜这是一个标签栏应用程序,每个选项卡有两个选项卡和一个导航控件?你使用了界面构建器吗?
如果是这种情况,您不需要声明导航控制器,因为您的视图控制器已作为第一个视图控制器位于其中。
试试吧:
[[self navigationController] pushViewController:fourth animated:YES];
答案 1 :(得分:0)
您是否已将navigationController2声明为属性?看起来它只是一个变量。如果您正在使用属性,则只能使用“self”。
@property (nonatomic, retain) UINavigationController navigationController2;// in .h
@synthesize navigationController2; //in .m