pushViewController不会导致新控制器绘制视图

时间:2011-10-03 05:08:58

标签: ipad uinavigationcontroller draw pushviewcontroller

前言:我没有使用* .xib文件。

我在类中实例化一个UINavigationController,它有效地充当了我的rootViewController'。这个' rootViewController'还有两个UITableViewController成员,它们在iPad屏幕的不同部分绘制。其中一个设置为导航控制器的根视图。我们称之为tableViewControllerA。

问题是,当我在有效的UINavigationController上调用pushViewController时,我认为没有效果: [tableViewControllerA.navigationController pushViewController:tableViewControllerX animated:YES];

我已经从我今天搜索过的帖子中收集过,这种推送方法应该会导致屏幕重绘堆栈controller.view的顶部。这不是我所看到的。

我的实现似乎存在脱节,现在是时候在我的环境中引用一个工作示例(xcode 4.0)。假设固定模板可以提供工作基础,我创建了一个新的基于导航的应用程序。我只是修改了didFinishLaunchingWithOptions:如下所示。

    UIViewController *view1 = [[UIViewController alloc] init];
    UIViewController *view2 = [[UIViewController alloc] init];

    view1.title = @"view1";
    view2.title = @"view2";

    [self.navigationController pushViewController:view1 animated:YES];
    [self.navigationController pushViewController:view2 animated:YES];

    self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:view1];

    [view1 release];
    [view2 release];

我发现了类似的结果。当我启动模拟器时,屏幕标题会读取self.window.rootViewController指向的标题。使用代码,生成的顶部屏幕的标题显示" view1"。当我initWithRootViewController:view2时,生成的顶部屏幕显示" view2"。

所以请告诉我,我是愚蠢的cuz xyz ...... 谢谢。

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

没有看到你的代码,我有两个理论:

  1. 执行推送时,语法和调用是错误的。将其用作模型:

    -(void)Examplemethod {
        AnotherClassViewController *viewController = [[[AnotherClassViewController alloc] initWithNibName:@"AnotherClassView" bundle:nil] autorelease];
    
        [self.navigationController pushViewController:viewController animated:YES];
    }
    
  2. 您永远不会将导航控制器添加到从不添加视图的视图层次结构中。请查看this