ios - how to hide button when clicked from another view -


i beginner of xcode programming. trying action, when click button view, button of b view hidden. know can use button.hidden = true; self view controller don't know how control button other view.

thanks

@ibaction func testbut(sender: uibutton) {     setting.hidden = false } 

before, create custom view button, button action , protocol as:

protocol customviewdelegate {     func buttonpressed (sender: anyobject) }  class customview: uiview {      @iboutlet weak var button: uibutton!     var delegate: customviewdelegate!      override func awakefromnib() {         super.awakefromnib()     }     class func loadviewfromxib() -> customview {         return nsbundle.mainbundle().loadnibnamed("customview", owner: self, options: nil)[0] as! customview     }     @ibaction func buttonpressed(sender: anyobject) {         self.delegate.buttonpressed(sender)   } } 

in viewcontroller.

class viewcontroller: uiviewcontroller, customviewdelegate {  var firstview: customview? var secondview: customview? override func viewdidload() {     super.viewdidload()     // additional setup after loading view, typically nib.      self.firstview = customview.loadviewfromxib()     self.secondview = customview.loadviewfromxib()      firstview!.frame = cgrectmake(0, 0, 100, 100)     secondview!.frame = cgrectmake(0, 200, 100, 100)      firstview!.delegate = self     secondview!.delegate = self      self.view.addsubview(firstview!)     self.view.addsubview(secondview!) }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  func buttonpressed(sender: anyobject) {     if (sender as! uibutton) == self.firstview!.button {         self.secondview?.button.hidden = true     }else {         self.firstview?.button.hidden = true     }   } } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -