Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting text to the UISearchBar when its firstresponder with controller change works weird
    text
    copied!<p>In my app i have <code>UITextField</code> on view of VC1(<code>UIViewController</code>). When i change text in textfield i call pushing of another controller VC2 with <code>UISearchBar</code> on its view. After pushing im assigning <code>UISearchBar</code> text to the textfield text from VC1.</p> <p>On xib my textfield already have some text "Test string".</p> <p>When I'm append VC1 textfield with any char - VC2 pushing and text on searchbar is normal.</p> <p>But when I'm press backspace key on iPhone keyboard - VC2 pushed and text on searchfield start deleting char by char, while whole string not been empted. It happend because delegate method calls recursively.</p> <p>How to fix that behaviour of <code>UISearchBar</code>? I mush to have searchbar active with keyboard opened when VC2 appears! It's main condition. Sure, if i'll remove <code>[self.searchBar becomeFirstResponder]</code> all will works fine.</p> <p>Some code here:</p> <pre><code>@implementation ViewController1 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString * resultString = [textField.text stringByReplacingCharactersInRange:range withString:string]; ViewController2 * vc2 = [ViewController2 new]; [self.navigationController pushViewController:vc2 animated:YES]; [vc2 loadText: resultString]; return NO; } @end @implementation ViewController2 - (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.searchBar becomeFirstResponder]; } - (void) loadText: (NSString *) text { self.searchBar.text = text; } @end </code></pre> <p>Sample source code of the problem: <a href="http://yadi.sk/d/NJmTLot73_vrE" rel="nofollow">http://yadi.sk/d/NJmTLot73_vrE</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload