View 从其他视图控制器调用UIBarButtonim

View 从其他视图控制器调用UIBarButtonim,view,call,uibarbuttonitem,View,Call,Uibarbuttonitem,我想在一个导航控制器上实现一个uiBarButtonim,它嵌入了一个带有三个选项卡的TabBar控制器,我想在它上实现一个操作,但是可以从所有视图调用它,从而在每个视图上实现不同的uiBarButtonim 我想要的是,当点击uibarbuttonite时,显示一个操作表,无论用户在哪个视图中,该操作表在所有视图上都是相同的 你能帮我一下吗?我对iOS和Swift编程非常陌生 谢谢大家! 好的,我想我回答了我自己的问题,非常简单。我只需创建一个自定义视图控制器文件,并与我的历史记录板上的Tab

我想在一个导航控制器上实现一个uiBarButtonim,它嵌入了一个带有三个选项卡的TabBar控制器,我想在它上实现一个操作,但是可以从所有视图调用它,从而在每个视图上实现不同的uiBarButtonim

我想要的是,当点击uibarbuttonite时,显示一个操作表,无论用户在哪个视图中,该操作表在所有视图上都是相同的

你能帮我一下吗?我对iOS和Swift编程非常陌生


谢谢大家!

好的,我想我回答了我自己的问题,非常简单。我只需创建一个自定义视图控制器文件,并与我的历史记录板上的TabBar视图关联,然后为UIButtonBarItem添加操作,如下所示:

import UIKit

class CustomTabBarViewControler: UITabBarController {


    @IBAction func showActionSheet(sender: UIBarButtonItem) {

        let myActionSheet = UIAlertController(title: "Log in", message: "How do you want to log in", preferredStyle: UIAlertControllerStyle.ActionSheet)

        let fbLoginButton = UIAlertAction(title: "Facebook", style: UIAlertActionStyle.Default)
            { (ACTION) in
                print("Facebook Button Tapped")
        }
        let googlePlusButton = UIAlertAction(title: "Google Plus", style: UIAlertActionStyle.Default) {
            (ACTION) in
            print("Google Plus Button Tapped")
        }
        let twitterButton = UIAlertAction(title: "Twitter", style: UIAlertActionStyle.Default) {
            (ACTION) in
            print("Twitter Button Tapped")
        }

        let cancelButton = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) {
            (ACTION) in
            print("Cancel Button Tapped")
        }

        myActionSheet.addAction(fbLoginButton)
        myActionSheet.addAction(googlePlusButton)
        myActionSheet.addAction(twitterButton)
        myActionSheet.addAction(cancelButton)

        self.presentViewController(myActionSheet, animated: true, completion: nil)
    }

}
这对我来说很好