<bdo id='OaxOH'></bdo><ul id='OaxOH'></ul>
    <tfoot id='OaxOH'></tfoot>

    <small id='OaxOH'></small><noframes id='OaxOH'>

    <i id='OaxOH'><tr id='OaxOH'><dt id='OaxOH'><q id='OaxOH'><span id='OaxOH'><b id='OaxOH'><form id='OaxOH'><ins id='OaxOH'></ins><ul id='OaxOH'></ul><sub id='OaxOH'></sub></form><legend id='OaxOH'></legend><bdo id='OaxOH'><pre id='OaxOH'><center id='OaxOH'></center></pre></bdo></b><th id='OaxOH'></th></span></q></dt></tr></i><div id='OaxOH'><tfoot id='OaxOH'></tfoot><dl id='OaxOH'><fieldset id='OaxOH'></fieldset></dl></div>
    1. <legend id='OaxOH'><style id='OaxOH'><dir id='OaxOH'><q id='OaxOH'></q></dir></style></legend>

    2. 以编程方式在 UIViewController 中添加 UINavigationController

      时间:2023-06-11
          <bdo id='MqqCw'></bdo><ul id='MqqCw'></ul>
        • <legend id='MqqCw'><style id='MqqCw'><dir id='MqqCw'><q id='MqqCw'></q></dir></style></legend>

              • <small id='MqqCw'></small><noframes id='MqqCw'>

                  <tbody id='MqqCw'></tbody>

              • <tfoot id='MqqCw'></tfoot>

                <i id='MqqCw'><tr id='MqqCw'><dt id='MqqCw'><q id='MqqCw'><span id='MqqCw'><b id='MqqCw'><form id='MqqCw'><ins id='MqqCw'></ins><ul id='MqqCw'></ul><sub id='MqqCw'></sub></form><legend id='MqqCw'></legend><bdo id='MqqCw'><pre id='MqqCw'><center id='MqqCw'></center></pre></bdo></b><th id='MqqCw'></th></span></q></dt></tr></i><div id='MqqCw'><tfoot id='MqqCw'></tfoot><dl id='MqqCw'><fieldset id='MqqCw'></fieldset></dl></div>
                本文介绍了以编程方式在 UIViewController 中添加 UINavigationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我目前的视图设置如下:

                @interface BlogViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{UITableView *mainTableView;}@property (nonatomic, 保留) UITableView *mainTableView;

                如您所见,它内部有一个 UITableView,我可以将所有数据加载到其中.但是,当我调用以下函数时:

                - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {SingleBlogViewController *viewController = [[SingleBlogViewController alloc] init];[self.navigationController pushViewController:viewController Animation:YES];//[self presentModalViewController:viewController Animation:YES];[viewController 发布];}

                什么都没有发生.出于某种原因,我的 UIViewController 内部的 UITableView 没有推送视图.这是因为它不是 UITableViewController 吗?我试着改成那个,还是不行.

                我错过了什么吗?

                解决方案

                我找到了这篇博文有助于展示如何在没有 Interface Builder 的情况下以编程方式创建和使用 UINavigationController.

                我希望文档和教程能够向我强调一些事情:

                • 当您创建 UINavigationController 时,您会免费获得一个 UIView 和 UINavigationBar(即您不需要单独添加它们并弄清楚如何将它们连接在一起).

                • 您将 myUINavigationController.view 属性添加为主"视图,然后将 UIViewController 推送/弹出到 UINavigationController 上,它们将自动显示为在 myUINavigationController.view UIView 中可见.

                • 当你将 UIViewController 推送到 UINavigationController 上时,UIViewController.navigationController 会被填充.如果你没有推送导航控制器上的视图,我猜该属性是空的.

                • 以编程方式将按钮添加到 UINavigationBar 的时间/地点不是您构建 UINavigationController 的时间和地点,而是由单个 UIViewControllers 当你推送到 UINavigationController 时加载它们.

                • 我只需要在第一个viewDidLoad方法中的UINavigationControllerUINavigationBar添加一个Done"按钮UIViewController 推送到 UINavigationController.我在第一个视图的 top 上按的任何 UIViewController 都会自动在其中有一个后退"按钮,以导航到被掩盖的 UIViewController.p>

                • 如果您在将 UIViewController 放入 UINavigationController 的堆栈之前设置了 title 属性.UINavigationBar 的标题将是您的视图的标题.同样,任何返回"按钮都会自动命名您要返回的视图,而不是一般地说返回".

                I currently have a view set up as the following:

                @interface BlogViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
                    UITableView *mainTableView;
                }
                
                @property (nonatomic, retain) UITableView *mainTableView;
                

                As you can see, it has a UITableView inside of it that I load all of my data to. However, when I call the following function:

                - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
                    SingleBlogViewController *viewController = [[SingleBlogViewController alloc] init];
                    [self.navigationController pushViewController:viewController animated:YES];
                    //[self presentModalViewController:viewController animated:YES];
                    [viewController release];
                }
                

                nothing happens. For some reason my UITableView inside of my UIViewController isn't pushing the view. Is this because it isn't a UITableViewController? I tried changing it to that, and it still didn't work.

                Am I missing something here?

                解决方案

                I found the first parts of this blog post useful for showing how to create and use a UINavigationController programmatically without Interface Builder.

                Some of the things I wish the docs and tutorials would have stressed to me:

                • When you create the UINavigationController you get a UIView and UINavigationBar for free (i.e. you don't need to separately add them and figure out how to hook them together).

                • You add the myUINavigationController.view property as the "main" view and then push/pop UIViewControllers onto the UINavigationController and they will automatically show up as visible in the myUINavigationController.view UIView.

                • When you push a UIViewController onto a UINavigationController, the UIViewController.navigationController is filled in. If you haven't pushed the view onto the navigation controller, I'm guessing that property is empty.

                • The time/place to programmatically add buttons to the UINavigationBar is not when and where you construct the UINavigationController, but rather by the individual UIViewControllers when they are loaded as you push onto the UINavigationController.

                • I only had to add a "Done" button to the UINavigationController's UINavigationBar in the viewDidLoad method of the first UIViewController pushed onto the UINavigationController. Any UIViewController I pushed on top of that first view automatically had a "back" button in the to navigate to the covered up UIViewController.

                • If you set the title property of your UIViewController before you put it on the UINavigationController's stack. The UINavigationBars title will be the title of your view. As well any "back" buttons will automatically name the view you are returning to instead of generically saying "back".

                这篇关于以编程方式在 UIViewController 中添加 UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:UINavigationBar 用动画改变 Tint 颜色 下一篇:如何获取 UINavigationBar 中后退按钮的宽度?

                相关文章

              • <i id='xowhl'><tr id='xowhl'><dt id='xowhl'><q id='xowhl'><span id='xowhl'><b id='xowhl'><form id='xowhl'><ins id='xowhl'></ins><ul id='xowhl'></ul><sub id='xowhl'></sub></form><legend id='xowhl'></legend><bdo id='xowhl'><pre id='xowhl'><center id='xowhl'></center></pre></bdo></b><th id='xowhl'></th></span></q></dt></tr></i><div id='xowhl'><tfoot id='xowhl'></tfoot><dl id='xowhl'><fieldset id='xowhl'></fieldset></dl></div>
                  <bdo id='xowhl'></bdo><ul id='xowhl'></ul>
              • <legend id='xowhl'><style id='xowhl'><dir id='xowhl'><q id='xowhl'></q></dir></style></legend>

                <small id='xowhl'></small><noframes id='xowhl'>

                    <tfoot id='xowhl'></tfoot>