ios - Checking if button is pressed to segue correct data -


hi may simple question , apologize if on here already, searched couldn't find answer tailors specific situation.

here issue. creating text adventure practice ios development using swift in xcode 6 , in case have text view in view controller can scroll bottom of , 2 buttons @ bottom of screen. point being if hit 1 button segues different scenario , alters general character stats class usercharacter defined in project altering basic data , vice versa other button.

thing in segue need check button user pressed know data segue can't quite figure out how that.

here have far, (i have passed data once didn't need make choice simple)

class routezeroviewcontroller: uiviewcontroller {  var character : usercharacter?  @ibaction func choiceonebutton(sender: anyobject) {     character?.strength += 3     character?.intelligence -= 2 } @ibaction func choicetwobutton(sender: anyobject) {     character?.agility += 2     character?.intelligence += 2     character?.courage -= 2 } @iboutlet weak var textview: uitextview! override func viewdidload() {     super.viewdidload()      // additional setup after loading view.      // set initial textview load @ top instead of middle/bottom     self.textview.scrollrangetovisible(0) }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  // mark: - navigation // in storyboard-based application, want little preparation before navigation override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {      // new view controller using [segue destinationviewcontroller].     // check button 1 push ????????     var thirdscenea = segue.destinationviewcontroller routeoneaviewcontroller     thirdscenea.character = character      // check button 2 push ????????     var thirdsceneb = segue.destinationviewcontroller routeonebviewcontroller     thirdsceneb.character = character     }  } 

any appreciated. thank you..

you need add segue view controller viewcontroller refer link : ios7, segue , storyboards - how create without button?

set tag property each button i.e. 1 , 2

on button click pass button

   @ibaction func choiceonebutton(sender: anyobject)  { character?.strength += 3 character?.intelligence -= 2  self.performseguewithidentifier("identifer", sender: sender) }    @ibaction func choicetwobutton(sender: anyobject) { character?.agility += 2 character?.intelligence += 2 character?.courage -= 2 self.performseguewithidentifier("identifer", sender: sender)  } 

in prepare segue method check

 override func prepareforsegue(segue: uistoryboardsegue?, sender: anyobject?)  {    var btn:uibutton=sender uibutton          if btn.tag==1         {             // first button clicked         }          if btn.tag==2         {             // second button clicked         }  } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -