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

发布于 2024-12-08 09:33:10 字数 1274 浏览 0 评论 0原文

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

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

问题是,当我在有效的 UINavigationController 上调用 PushViewController 时,我看不到任何效果: [tableViewControllerA.navigationController PushViewController:tableViewControllerX 动画:是];

我从今天搜索的帖子中收集到,这个推送方法应该反过来导致屏幕重绘堆栈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”。

所以请告诉我我很愚蠢,因为xyz...... 谢谢。

Preface: I am not using *.xib files.

I instantiate a UINavigationController in a class that effectively serves as my 'rootViewController'. This 'rootViewController' also has two UITableViewController members that are drawn on different sections of the iPad screen. One of which is set as the root view for the navigation controller. Let's call it tableViewControllerA.

The problem is, when I invoke pushViewController on a valid UINavigationController, I see no effect:
[tableViewControllerA.navigationController pushViewController:tableViewControllerX animated:YES];

I've gathered from the posts I've searched today, that this push method should in turn cause the screen to redraw the top of stack controller.view. This is not what I'm seeing.

It seemed there was a disconnect in my implementation, and it was time to reference a working example in my environment (xcode 4.0). Assuming the canned templates would provide a working basis, I created a new navigation-based applications. I simply modified didFinishLaunchingWithOptions: as follows.

    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];

I found similar results. When I launch the simulator the screen title reads the title of whatever the self.window.rootViewController is pointing at. With the code as is, the title of the resulting top screen reads "view1". When I initWithRootViewController:view2, the resulting top screen reads "view2".

So please tell me I'm stupid cuz xyz...
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

許願樹丅啲祈禱 2024-12-15 09:33:10

在没有看到你的代码的情况下,我有两种理论:

  1. 当你进行推送时,你的语法和调用是错误的。以此作为模型:

    -(void)示例方法 {
        AnotherClassViewController *viewController = [[[AnotherClassViewController alloc] initWithNibName:@"AnotherClassView" bundle:nil] autorelease];
    
        [self.navigationController PushViewController:viewController 动画:是];
    }
    
  2. 您永远不会将导航控制器添加到视图层次结构中,视图层次结构也永远不会添加视图。看看这个

Without seeing your code, I have 2 theories:

  1. Your syntax and calls are wrong when you do the push. Use this as a model:

    -(void)Examplemethod {
        AnotherClassViewController *viewController = [[[AnotherClassViewController alloc] initWithNibName:@"AnotherClassView" bundle:nil] autorelease];
    
        [self.navigationController pushViewController:viewController animated:YES];
    }
    
  2. You are never adding the navigation controller to the view hierarchy which never adds the view either. Take a look at this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文