an alternative to keyboard_enter_text on iOS 7

261 views
Skip to first unread message

Joshua Moody

unread,
Aug 10, 2013, 1:41:24 PM8/10/13
to calaba...@googlegroups.com
playback is not supported (yet?) on iOS 7.  this means that keyboard_enter_text is not available on iOS 7

we can use something like:

query("view marked:'my view id'", {setText:'some text'}) 

to set the text of the a UITextField or UITextView, but no keyboard events are trigger so delegate methods like:

UITextFieldDelegate textField: shouldChangeCharactersInRange: replacementString:

are not called.  

i was poking around in briar today and came up with a temporary solution:

def briar_keyboard_set_text (text, view_id, &do_for_each_char)
  if gestalt.is_ios7?
    query_str = "view marked:'#{view_id}'"
    accum = ''
    text.chars.to_a.each { |char|
      accum << char
      query(query_str, {setText:accum})
        do_for_each_char.call(view_id, accum)
        @text_entered_by_keyboard = accum
        sleep(0.05)
      }
  else
    pending 'this is hack for iOS 7 (playback not available yet) - use briar_keyboard_enter_text'
  end
end

example:

# i have a text field with a delegate that itself has a delegate that responds when the text has changed
# the textChangedDelegate handleTextFieldDidChangeWithSearchString method reloads a table view
briar_keyboard_set_text(behavior, 'add/search') { |view_id, text|
  query("view marked:'#{view_id}'", :delegate, :textChangedDelegate, [{handleTextFieldDidChangeWithSearchString:text}])
}

this pattern is not very common, but i thought i would share it.

tejasvi manmatha

unread,
Jan 20, 2014, 9:30:11 AM1/20/14
to calaba...@googlegroups.com
set_text "textField index:1", "asd"

set text is deprecated but still works on IOS7 (simulator) , I havent tested on device though.

Cheers,
Tej

Chathura Palihakkara

unread,
Feb 27, 2014, 5:54:37 AM2/27/14
to calaba...@googlegroups.com
This query    query("view marked:'#{view_id}'", :delegate, :textChangedDelegate, [{handleTextFieldDidChangeWithSearchString:text}]) doesn't work for me. I want to fire the UITextView delegate shouldChangeTextInRange something like  query(textBox,:delegate, [{:textView => :__self__},{:shouldChangeTextInRange=> :NSMakeRange(0,1)},{:replacementText => text}])   but argument NSRange cause a problem and crash the simulator. Please help me with this problem.

Thanks.

Joshua Moody

unread,
Feb 27, 2014, 6:19:13 AM2/27/14
to calaba...@googlegroups.com
I do not recommend this approach.

Use the keyboard_enter_text function.

If you need to set the text directly, use the set_text function.  
Reply all
Reply to author
Forward
0 new messages