PushViewController 不会导致新控制器绘制视图
前言:我没有使用 *.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是一些参考和建议:
基于导航的应用程序的简单教程:
http ://humblecoder.blogspot.com/2009/04/iphone-tutorial-navigation-controller.html
这是另一个创建分步导航控制器并添加视图的方法:
http://www.icodeblog.com/2008/ 08/03/iphone-programming-tutorial-transitioning- Between-views/
这里对导航+标签栏控制器进行了一些改进:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CombiningToolbarandNavigationControllers/CombiningToolbarandNavigationControllers.html
Here are some references and suggestions:
Simple tutorial for navigation based application:
http://humblecoder.blogspot.com/2009/04/iphone-tutorial-navigation-controller.html
Here is another one to create the step by step navigation controller and adding the views:
http://www.icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning-between-views/
and here a bit advance with navigation + tab bar controller:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CombiningToolbarandNavigationControllers/CombiningToolbarandNavigationControllers.html
在没有看到你的代码的情况下,我有两种理论:
当你进行推送时,你的语法和调用是错误的。以此作为模型:
您永远不会将导航控制器添加到视图层次结构中,视图层次结构也永远不会添加视图。看看这个。
Without seeing your code, I have 2 theories:
Your syntax and calls are wrong when you do the push. Use this as a model:
You are never adding the navigation controller to the view hierarchy which never adds the view either. Take a look at this.