ios - Is it possible to get button title from IB in class? -


i have several buttons titles 0 - 9 , in custom uibutton class want able use switch check button title. buttons created in storyboard. uibutton class looks like:

protocol numpaddelegate: class {     func changevalue() }  class numpadbutton: uibutton, numpaddelegate {      let initial = string()          // want assign title of button here     var alternative = string()     var change: bool = false {         didset {             let title = change ? alternative : initial             settitle(title, forstate: .normal)         }     }      func changevalue() {         change = !change     } } 

is there way or i'll have programmatically create buttons? i'm trying limit use of custom uibutton class don't have create 1 each of buttons.

edit:

as requested, code of when button pressed:

@ibaction func buttonnumber(sender: uibutton) {         let value = sender.titlelabel!.text!          switch value {         case "c": orderlabel.text = ""         default: orderlabel.text = orderlabel.text.map { count($0) < 10 ? $0 + value : $0 } ?? value         }          if let check = orderlabel.text {             inputresult.removeall(keepcapacity: false)              index in 0..<items.count {                 let id = items[index].id                 if id.lowercasestring.hasprefix(check.lowercasestring) {                     inputresult += [items[index]]                 }             }              numpadtableview.reloaddata()         }     } 

what i'm trying is, when swipe buttons want titles change alternative string i.e. button title 1 change , button title 2 change b.

don't know you're going here's example i've created outlets each numpadbutton , added them array.

class viewcontroller: uiviewcontroller {  @iboutlet weak var button1: numpadbutton! @iboutlet weak var button2: numpadbutton! @iboutlet weak var button3: numpadbutton! @iboutlet weak var button4: numpadbutton!  var array: nsmutablearray = []  override func viewdidload() {     super.viewdidload()     array.addobject(button1)     array.addobject(button2)     array.addobject(button3)     array.addobject(button4) } 

each button has title of either "1", "2", "3" or "4". can check title via case statement so:

override func viewwillappear(animated: bool) {      item in array {          var button = item as! uibutton          switch button.currenttitle! {             case "1":                 println("this button has title of 1")             case "2":                 println("this button has title of 2")             case "3":                 println("this button has title of 3")             case "4":                 println("this button has title of 4")             default:                 println("default case")         }     } } 

}

this 1 way use case statement access titles of uibuttons , adjust application whatever functionality want (e.g. through ibaction, etc.).


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -