Set UITabBarController created in Interface Builder as delegate

后端 未结 4 1884
北荒
北荒 2021-01-05 08:33

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 progra

4条回答
  •  悲&欢浪女
    2021-01-05 08:42

    You can quickly and easily create a new TabBarController Delegate class and connect it as the delegate in the storyboard.

    1. Create a new class :

      class TabBarControllerDelegate: NSObject, UITabBarControllerDelegate {

    2. In IB, add an object from the object library to the list of View Controller on the left (note: search "object", it's a yellow cube).

    3. Change the class of this object (your yellow cube in IB) to TabBarControllerDelegate

    4. In IB navigate to your Tab Bar Controller Scene. From the Connection Inspector, drag the delegate circle to the new object you added in Step 3.

    5. Implement your delegate methods in your TabBarControllerDelegate class. Done!

      func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController)->Bool {
         println("Selected a new tab")
      

      }

提交回复
热议问题