UINavigationController 未推送/显示视图

发布于 2024-11-28 12:52:20 字数 1683 浏览 0 评论 0原文

iOS 和 Objective C 新手。在 XCode 模拟器中开发 iPad 应用程序时,自定义 UINavigationController 出现问题。非常感谢您的帮助!

  1. 在 XCode 中创建项目(基于视图的应用程序)。应用程序当前有两个视图。主页和详细信息视图。想要一个像 Facebook 或 Linkedin iPhone 应用程序主页这样的主页...主页上有一堆图标/图像,单击每个图标/图像即可获取更多详细信息

  2. (知识有限)结论是主页不能是 TableView、SplitView 或 TabBarView。不想在主页中出现任何选项卡或表格视图样式(如上所述)。因此无法使用“基于导航的应用程序”模板启动 XCode 项目

  3. 未将 IB 中的 UI 元素添加到 MainWindow.xib,rathar 主页 UI 元素位于项目模板创建的 otherView.xib 中。项目模板在 appDelegate.didFinishLaunchingWithOptions 方法中将 rootViewController 分配给 otherViewController。 self.window.rootViewController = otherViewController

  4. 通过IB向otherView.xib添加了一个NavigationController。添加了导航控制器的出口。 otherView.h 有以下内容 UINavigationController *navigationController; @property(非原子,保留)IBOutlet UINavigationController *navigationController; navigationController的referencingOutlet连接到File's Owner

  5. 当应用程序启动时,主页(由其他ViewController提供服务)出现。当单击主页中的图标(后面带有按钮的 ImageView)时,如果我调用

    ,详细信息视图不会显示

    [self.navigationController PushViewController:DetailViewController 动画:YES]; (在操作方法中,处理该按钮的 touchUpInside。)

则会显示详细信息视图

但是如果我执行self.view = DetailViewController.view; , 或
[self.view addSubview:DetailViewController.view];

所以 DetailView 加载它的 nibfile 等似乎不是问题。 在按钮单击/触摸事件捕获等方面也没有问题。

A. 当我在调试器中检查导航控制器时,它的堆栈中有两个视图控制器,根视图/主页位于索引 0 处,详细视图位于索引 1 处。不为空。关于我缺少什么有什么想法吗?

B. 我是否需要在主页(在其视图中添加导航控制器)和详细视图中添加导航栏?我已将导航栏添加到详细视图中。我不需要主页 UI 中的导航栏。

C. 当通过 addSubview 调用或 self.view 分配(如上所述)显示详细信息视图时,导航栏不会显示后退按钮(应该显示“Home”)。 两个视图控制器都使用 self.Title = "Home" 或 "Detail" 设置适当的 title 。

感谢您的帮助。谢谢

New to iOS and objective C. Trouble with custom UINavigationController while developing an iPad app in XCode simulator. Appreciate your help greatly !

  1. Created project (view based application) in XCode. Application currently has two views. Home Page and a Detail View. Want a Home Page like Facebook or Linkedin iPhone App Home page...where you have bunch of icons/images on the home page, and click on each to get more details

  2. (With limited knowledge) concluded Home page can't be TableView, SplitView or TabBarView. Don't want any tabs or table view style in Home page (as explained above). So couldn't start XCode project with "Navigation Based Application" template

  3. Didn't add UI elements from IB to MainWindow.xib, rathar homepage UI elements are in the otherView.xib created by the project template. The project template, assigns rootViewController to otherViewController within appDelegate.didFinishLaunchingWithOptions method. self.window.rootViewController = otherViewController.

  4. Added a NavigationController through IB to otherView.xib. Added outlet for navigationController. otherView.h has following
    UINavigationController *navigationController;
    @property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

    referencingOutlet for navigationController is connected to File's Owner

  5. When App is launched Home Page (served by otherViewController) comes up. When clicking on an icon in Homepage (an ImageView with Button behind), Detail View doesn't show up, if I call

    [self.navigationController pushViewController:DetailViewController animated:YES];
    (within the action method, that's handling touchUpInside for that button.)

but detail view shows up if I do either

self.view = DetailViewController.view;
or
[self.view addSubview:DetailViewController.view];

So doesn't seem to be a problem with DetailView loading it's nibfile etc.
No problem also in button click/touch event capture etc.

A. When I examine the navigationcontroller in the debugger, it has both the two viewControllers in its stack, with rootView/ Home page at index 0, and Detail View at index 1. navigationController is not null. Any ideas on what am I missing ?

B. Do I need to add a navigationBar to both the home page (in whose view navigation controller is added) and the detail view ? I have added a navigationBar to the detail view. I don't need a navigation bar in the home page UI.

C. When the detail view shows up through the addSubview call or self.view assignment (as mentioned above), the navigationBar doesn't show the back button (which should say "Home").
Both view Controller is setting appropriate title , using self.Title = "Home" or "Detail".

Appreciate your help. Thanks

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

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

发布评论

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

评论(2

但可醉心 2024-12-05 12:52:20

在appDelegate中,您需要将导航控制器设置为一个属性,然后

self.window.rootViewController = self.navigationController;

在application didFinishLaunchingWithOptions:方法中 写入:
然后将 otherViewController 推入其堆栈。我认为你犯的错误是将 UINavigationController 添加到 UIView 而不是相反,这是正确的方法!

In the appDelegate, you need to make navigation controller a property and then write:

self.window.rootViewController = self.navigationController;

in application didFinishLaunchingWithOptions: method.
Then push otherViewController onto its stack. I think the mistake you're making is adding UINavigationController to UIView instead of the other way around, which is the correct way!

苏别ゝ 2024-12-05 12:52:20

你也应该在你的 xib 文件中做什么,
确保您的视图位于导航控制器中,

您的 xib 文件树应如下所示:

  • 您的 appdelegate
  • 窗口
  • 导航控制器
  • 导航栏
  • 和您的 rootviewcontroller

what you should do too in your xib file,
make sur that you view is in a navigationcontroller

the tree of your xib file should like this :

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