UINavigationController,UITableView并没有显示下一个视图

时间:2009-07-31 11:35:28

标签: iphone uitableview uinavigationcontroller uitabbarcontroller

我遇到表格问题,并在用户触摸表格单元格时显示另一个视图。我在主视图中使用UITabBarController来显示不同的视图。然后,当用户选择UITableView视图以显示表格单元格选择中的下一个视图时,我使用UINavigationController。

我的问题是:当他们选择表格单元格时,单元格会突出显示,并且不会显示下一个视图。我正在使用IB。我发现的所有示例都是这样做的,除了示例工作!

我将控制器加载到带有Dictionary的NSMutableArray中。我也通过直接创建视图控制器而不是使用数组项来尝试此代码。相同的结果......

我检查了目标控制器(Calc1ViewController)以确保控制器没有任何问题。直接显示时,控制器(Calc1ViewController)显示正确。

这是一些代码.....

字典中视图控制器的初始化:

Calc1ViewController *calc1ViewController = [[Calc1ViewController alloc] init];
[menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                     NSLocalizedString(@"SSC - page 1",@""), @"title",
                     calc1ViewController, @"viewController",
                     nil]];
[calc1ViewController release];

我也试过这个而不使用字典 - 创建一个视图控制器代替[[menuList objectAtIndex:...]; line - 通过这样创建视图控制器:

Calc1ViewController *targetViewController = [[Calc1ViewController alloc] init];


// the table's selection has changed, switch to that item's UIViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *targetViewController = [[menuList objectAtIndex: indexPath.row] objectForKey:@"viewController"];
    [[self navigationController] pushViewController:targetViewController animated:YES];
    targetViewController = nil;
}

导航控制器在AppDelegate中定义,并通过IB连接到RootViewController。

当我选择一个表行时,它会在调试器中显示执行pushViewController代码,但是下一个视图没有显示。这是一个例子:

alt text http://thecoolestcompany.com/ssc-table-view.jpg

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

终于想通了......

我在同一级别上有UINavigationController和UITabBarController。将导航控制器作为子项移动到标签栏控制器后,一切正常。您可以根据需要向选项卡栏添加任意数量的导航控制器。在IB中有点令人困惑。您需要将NavigationController拖动到TabBar中,将其作为新的Tab Bar项目。

答案 1 :(得分:0)

使用您提供的代码并不多。我唯一能想到的就是没有查看更多的代码,可能是你没有正确地初始化你的视图控制器(你的字典中的那个),或者根本没有,或者你正在访问的字典没有正确的... < / p>

答案 2 :(得分:0)

调用pushViewController时[self navigationController]的值是多少?它没有?

将targetViewController传递给pushViewController时的值是什么?它没有?