ios - Switch case in swift -


these uibuttons

@iboutlet weak var btnprogressdate: uibutton! @iboutlet weak var btncloseddate: uibutton! 

i have dragged these 2 buttons action as:

@ibaction func btnclicked(sender: uibutton) {     let tag = sender.tag     self.clearpopups()     switch (tag) {             case 1:         self.datepicker.hidden = false         self.datepicker.datepicker.maximumdate = nil         self.datepicker.datepicker.minimumdate = nil          if(self.healthactionplancondition.dateclosed != nil)         {             self.datepicker.datepicker.maximumdate = self.healthactionplancondition.dateclosed         }         if(self.healthactionplancondition.nextprogressreviewdate != nil)         {             self.datepicker.datepicker.setdate(self.healthactionplancondition.nextprogressreviewdate, animated: true)         }         self.selectedbtn = self.btnprogressdate     case 2:         self.datepicker.hidden = false         if(self.healthactionplancondition.nextprogressreviewdate != nil)         {             self.datepicker.datepicker.minimumdate = self.healthactionplancondition.nextprogressreviewdate         }          if(self.healthactionplancondition.dateclosed != nil)         {             self.datepicker.datepicker.setdate(self.healthactionplancondition.dateclosed, animated: true)         }         self.datepicker.datepicker.maximumdate = nil         self.selectedbtn = self.btncloseddate     default:         print("proper btn not found")     }   } 

but every time clicked of buttons default case executed. totally new swift. doing wrong here??

instead of using tag, in action method can use iboutlet of uibutton have created way.

@ibaction func btnclicked(sender: uibutton) {     self.clearpopups()     if sender == btnprogressdate {         self.datepicker.hidden = false         self.datepicker.datepicker.maximumdate = nil         self.datepicker.datepicker.minimumdate = nil          if(self.healthactionplancondition.dateclosed != nil)         {             self.datepicker.datepicker.maximumdate = self.healthactionplancondition.dateclosed         }         if(self.healthactionplancondition.nextprogressreviewdate != nil)         {             self.datepicker.datepicker.setdate(self.healthactionplancondition.nextprogressreviewdate, animated: true)         }         self.selectedbtn = self.btnprogressdate     }     else if sender == btncloseddate {         self.datepicker.hidden = false         if(self.healthactionplancondition.nextprogressreviewdate != nil)         {             self.datepicker.datepicker.minimumdate = self.healthactionplancondition.nextprogressreviewdate         }          if(self.healthactionplancondition.dateclosed != nil)         {             self.datepicker.datepicker.setdate(self.healthactionplancondition.dateclosed, animated: true)         }         self.datepicker.datepicker.maximumdate = nil         self.selectedbtn = self.btncloseddate     }     else {         print("proper btn not found")     } }     

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -