【问题标题】:UINavigationController, UITableView and not showing the next viewUINavigationController,UITableView 并且不显示下一个视图
【发布时间】:2010-11-15 18:31:18
【问题描述】:

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

我的问题是:当他们选择表格单元格时,单元格被突出显示并且下一个视图没有出现。我正在使用 IB。我发现的所有示例都以与我相同的方式执行此操作,除了示例有效!

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

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

这是一些代码.....

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

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

我也在不使用字典的情况下尝试了这个——创建一个视图控制器来代替 [[menuList objectAtIndex:...];行——通过像这样创建视图控制器:

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

有什么想法吗?

【问题讨论】:

    标签: iphone uitableview uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    终于明白了……

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

    【讨论】:

      【解决方案2】:

      调用pushViewController时[self navigationController]的值是多少。是零吗?

      targetViewController 传递给 pushViewController 时的值是多少。是零吗?

      【讨论】:

      • 看起来 targetViewController 不为零,并且是我正在显示的视图控制器的正确视图控制器。我在使用 navigationController 时遇到问题。它最初在 App Delegate 中定义为 UINavigationController *calcPageNavigation;
      【解决方案3】:

      您提供的代码没什么可参考的。在不查看更多代码的情况下,我唯一能想到的是,您可能没有正确初始化视图控制器(字典中的那个),或者根本没有初始化,或者您正在访问的字典不是正确的......

      【讨论】:

      • 添加了更多代码——如果有其他代码需要帮助,请告诉我,我一定会添加——谢谢!
      猜你喜欢
      • 1970-01-01
      • 2011-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多