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

    1. <small id='1s4h5'></small><noframes id='1s4h5'>

      1. <tfoot id='1s4h5'></tfoot>

        将在 Interface Builder 中创建的 UITabBarController 设置为委托

        时间:2023-09-12

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

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

            <legend id='zRpVT'><style id='zRpVT'><dir id='zRpVT'><q id='zRpVT'></q></dir></style></legend>
              <bdo id='zRpVT'></bdo><ul id='zRpVT'></ul>

                  本文介绍了将在 Interface Builder 中创建的 UITabBarController 设置为委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用 Tab Bar 模板创建了我的 iOS 应用程序,所以这里是带有栏按钮的 UITabBarController.一个问题是如何将其设置为委托.我在 SO 发现它必须在 AppDelegate 中以编程方式设置,但我相信这是不可能的,因为我无法访问 Tab Bar Controller 作为出口.

                  I created my iOS app with Tab Bar template, so here is UITabBarController with bar buttons. An issue is how to set it as delegate. I found at SO that it has to be set programmatically in AppDelegate, but I believe it's impossible, because I've got no access to Tab Bar Controller as outlet.

                  我为 @interface(ViewController 和 AppDelegate)添加了适当的值,但不知道下一步该做什么.

                  I added proper value to @interface (both ViewController and AppDelegate), but doesn't know what to do next.

                  @interface ViewController : UIViewController <UITabBarControllerDelegate>
                  

                  我希望我不必摆脱整个应用程序模板,并且可以将在 IB 中创建的 Tab Bar Controller 设置为委托.

                  I hope I don't have to get rid of whole app template and it's possible to set Tab Bar Controller created in IB to be delegate.

                  正是我想让它委托在标签选择事件上创建,如下所示:

                  Exactly I want to make it delegate to create on tab select event like this:

                  - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
                  

                  有什么想法吗?

                  推荐答案

                  我不记得确切的 Xcode 的 Tab Bar 模板设置,但是在你的 AppDelegate 中你可以访问你的窗口的 rootViewController,将其转换为 UITabBarController,然后将其委托设置为您的 AppDelegate 或任何其他视图控制器.

                  I don't remember exactly the Xcode's Tab Bar template set up, but in your AppDelegate you can access to your window's rootViewController, cast it to a UITabBarController, and then set its delegate to your AppDelegate or to any other view controller.

                  类似这样的:

                  UITabBarController *tabBarController = 
                      (UITabBarController *)[[self window] rootViewController];
                  [tabBarController setDelegate:self]; // In this example your app delegate would implement the UITabBarControllerDelegate protocol.
                  

                  编辑

                  如果你想将你的 ViewController 实例设置为委托:

                  If you want to set your ViewController instance as the delegate:

                  UITabBarController *tabBarController = 
                          (UITabBarController *)[[self window] rootViewController];
                  // I assume you have your ViewController instance set as the first view controller of your tab bar controller
                  // No need for a cast here since objectAtIndex: returns id, but of course you must implement the UITabBarController protocol in your ViewController.
                      [tabBarController setDelegate:[[tabBarController viewControllers] objectAtIndex:0]]];
                  

                  编辑 2从您的 ViewController 本身,您可以将选项卡栏控制器的委托设置为 rdelmar 注释.请记住,这不能在 init 方法中完成,因为视图控制器尚未在选项卡栏控制器中.正确的位置是 viewDidLoad 但因此在 ViewController 视图加载之前不会执行...

                  EDIT 2 From your ViewController itself you can set the tab bar controller's delegate as rdelmar comments. Just keep in mind that this cannot be done in the init method because the view controller is not in the tab bar controller yet. The proper place would be viewDidLoad but therefore it will not be executed until the ViewController view loads...

                  self.tabBarController.delegate = self;
                  

                  这篇关于将在 Interface Builder 中创建的 UITabBarController 设置为委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:您如何连接“代表"?UITextView 的出口到实现 UITextViewDelegate 协议的类? 下一篇:何时在 NSURLConnection 委托上调用 release?

                  相关文章

                1. <tfoot id='KhRKQ'></tfoot>
                  <legend id='KhRKQ'><style id='KhRKQ'><dir id='KhRKQ'><q id='KhRKQ'></q></dir></style></legend>

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

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

                    • <bdo id='KhRKQ'></bdo><ul id='KhRKQ'></ul>