ios - Call method when user changes focus from on textfield to another (RubyMotion) -


i'm using rubymotion (had been writing obj c in xcode i'm collaborating wants use rubymotion due bkgd in ruby)

i have viewcontroller 2 textfields. need have whenever user switches being in textfield1 textfield2 if condition of textfield1 isn't met, error label shows (i use self.errorlabel.show this). know how write condition statements not know how know when user switches next textfield.

i thought use:

if ([textfield1 isfirstresponder] && (textfield1 != touch.view))      log( 'left textfield1' ) end  if ([textfield2 isfirstresponder] && (textfield2 != touch.view))      log( 'left textfield2' )  end 

from question detect uitextfield lost focus no such luck. know i'm using rubymotion there differences.

how work? don't think i'm searching right keywords because seems developers use time yet i'm not finding results.

thank available.

update: thinking using method:

- (void)textfielddidendediting:(uitextfield *)textfield 

in rubymotion: def textfielddidendediting( textfield )

i used log() determine indeed let me know user has changed 1 textfield next. need couple of tweaks can specify textfield left.

you need set delegate of each of text fields view controller class, implement textfielddidendediting method. here's working example:

class myviewcontroller < uiviewcontroller   attr_accessor :textfield1, :textfield2    def viewdidload      @textfield1 = uitextfield.alloc.initwithframe([[10, 100], [300, 40]])     # customize text field...     @textfield2 = uitextfield.alloc.initwithframe([[10, 150], [300, 40]])     # customize text field...     view.addsubview(@textfield1)     view.addsubview(@textfield2)      @textfield1.delegate = self     @textfield2.delegate = self   end    def textfielddidendediting(textfield)     if textfield == @textfield1       puts 'left textfield1'     elsif textfield == @textfield2       puts 'left textfield2'     end   end end 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -