Call UIBarButtonItem from other view controller -
i want implement uibarbuttonitem on navigation controller (father) have embed tabbar controller 3 tabs, , want implement action on it, can called views instead implement different uibarbuttonitem on each view.
what want when uibarbuttonitem tapped show actionsheet same on views no matter in view user be.
can me this, i'm new on ios , swift programming.
thank you!
ok, think answer own question, , easy. create custom view controller file , associated tabbar view on history board , add action uibuttonbaritem this:
import uikit class customtabbarviewcontroler: uitabbarcontroller { @ibaction func showactionsheet(sender: uibarbuttonitem) { let myactionsheet = uialertcontroller(title: "log in", message: "how want 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) } }
and works fine me.
Comments
Post a Comment