【问题标题】:UINavigationController won't push other view controllers?UINavigationController 不会推送其他视图控制器?
【发布时间】:2012-07-08 19:48:58
【问题描述】:

所以我在我的应用程序的委托中创建了一个 UINavigationController 并使用我的 RootViewController 实例对其进行了初始化。 UINavigationController 被添加为应用程序 UIWindow 的子视图。 (如果这很重要,我的 RVC 有一个自定义初始化程序。)

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
              _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

              _viewController = [[RootViewController alloc] initWithPath:@"/private/var/mobile/"];
              _viewController.title = @"mobile";

              UINavigationController *nav1 = [[[UINavigationController alloc] initWithRootViewController:_viewController] autorelease];

              //This part I'm not sure about as well
              [_window addSubview:nav1.view];
              [_window makeKeyAndVisible];

    return 0;
    }

有了这些信息,我正在尝试将另一个 RVC 实例从 UITableView 推送到导航堆栈,如下所示:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
              //I've tried it without the if statement as well
              if(indexPath.section == 0){
                      RootViewController *detailView = [[RootViewController alloc] initWithPath:launchDirectory];
                      detailView.title = relativeDirectory;
                      [self.navigationController pushViewController:detailView animated:YES];

另外,我的 RVC tableview 的数据源和委托已设置为“self”。

我的问题是:为什么即使我选择了表格上的一行,视图仍然保持不变? 该表不会推送到新表,并且在选择一行后我仍然看到相同的单元格内容。换句话说,什么都没有发生……

感谢您的帮助。

【问题讨论】:

    标签: ios uitableview sdk uinavigationcontroller


    【解决方案1】:

    您的导航控制器很可能是nil,这意味着您的-autorelease 有点过分。通常,导航控制器会持续存在,直到调用委托的 dealloc 方法,因此将其释放。

    【讨论】:

    • setRootViewController 不在我的 UIWindow 类中。为了兼容性,我使用 SDK 3 顺便说一句。
    • 然后忽略第一部分。第二部分仍然适用。
    • 这是一个新实例。一个新变量。这就是为什么我为它创建了一个自定义初始化程序。自定义初始值设定项创建用于填充表的数组。 -second- RVC 实例具有与第一个不同的数组。我读到你可以推送同一类的不同实例。有点像使用多个 UIAlertViews。 UIViewControllers 也不例外。只是为了测试这个理论,我创建了一个与 RVC 类相同的 DetailView 类。仍然无法从父视图控制器 (RVC) 推送 DetailView 类。
    • 那么你的 navigationController 不知何故为零。
    • 无论如何要解决这个问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 2016-07-29
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    相关资源
    最近更新 更多