2011-05-28 65 views
0

我正在制作一个具有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

您是否已将navigationController2声明为属性?看起来它只是一个变量。如果您使用属性,则只能使用“自我”。

@property (nonatomic, retain) UINavigationController navigationController2;// in .h 
@synthesize navigationController2; //in .m 
+0

我做到了,我AppDelegate.m。你有什么想法吗? – Evan 2011-05-28 01:46:01

+0

由于navigationController2不是真正的选择器,而是属性,请尝试使用“。”。记法(self.navigationController2)。如果你的综合函数超出了这个函数被调用的地方,那么你将不会收到任何错误,否则你会得到一个错误而不是一个警告。我猜你上面粘贴的函数也在AppDelegate.m – Gary 2011-05-28 02:13:38

+0

是的,我认为你没有将navigationController2声明为任何“self”类的属性。 (它可能与拼写错误一样简单,或者您可以在不同的类中声明该类,并且当前类不会从宣称的类继承。) – 2011-05-28 02:49:40

1

由于您使用了两个导航控制器,我猜这是一个带有两个选项卡和一个导航控制的标签栏应用程序?你为此使用了界面生成器吗?

如果这样的话你不需要声明你的导航控制器,因为你的视图控制器已经在它们里面作为第一个视图控制器。

试试看:

 
[[self navigationController] pushViewController:fourth animated:YES]; 
+0

我不使用IB唯一代码。你觉得我做错了什么? – Evan 2011-05-28 10:07:59

+0

'navigationController'是'UIViewController'对象的一个​​属性,它给了我们它所包含的'UINavigationController'对象。另一方面,'navigationController2'是你的主视图控制器类中的一个实例变量,它是对同一个对象的引用。 – 2011-05-28 10:10:21