ios - Multiple buttons to single IBAction - How to change background of the previous tapped button? -


i have group of buttons user can tap, calculator.

the app collect series of 2 buttons taps. select card deck. 1st tap ace through king. 2nd tap suit.

when 1st button tapped, change background yellow (the rank). when 2nd button tapped, save 2 selections pair , append string (the suit).

once 2nd button tapped, want change 1st tapped button blue.

with buttons linked single ibaction 'buttontapped', can't change 1st button background blue, when tapping 2nd button. (i ok 2nd button changing buttons linked ibaction blue)

@ibaction func buttontapped(thebutton: uibutton) {      var buttondump = thebutton.titlelabel!.text!     var firstchar = array(buttondump)[0]      if firstchar == "♠️" || firstchar == "♥️" || firstchar == "♦️" || firstchar == "♣️" {     // must 2nd tap, lets change 1st tapped bg blue         self.n2.text = buttondump         thebutton.backgroundcolor = uicolor.bluecolor()      } else {          self.n1.text = buttondump         thebutton.backgroundcolor = uicolor.yellowcolor()     } 

the thebutton parameter button tapped user. button change background yellow, need keep reference button, , set blue when second button tapped.

something this:

var firstbutton: uibutton?  @ibaction func buttontapped(thebutton: uibutton) {      var buttondump = thebutton.titlelabel!.text!     var firstchar = array(buttondump)[0]      if firstchar == "♠️" || firstchar == "♥️" || firstchar == "♦️" || firstchar == "♣️" {         // must 2nd tap, lets change 1st tapped bg blue         //self.n2.text = buttondump          // change first button blue         if( self.firstbutton != nil ) {             self.firstbutton!.backgroundcolor = uicolor.bluecolor()         }     } else {         //self.n1.text = buttondump          // keep reference first button         self.firstbutton = thebutton         self.firstbutton!.backgroundcolor = uicolor.yellowcolor()     } } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -