0

I came across this issue a long time ago, and fixed it, but now I have no clue how I did it, and I'm coming across it in another controller.

I am using the following code to make the keyboard automatically show up when I show my view that as a search bar:

[self.rootController.changeClientViewController.searchDisplayController.searchBar becomeFirstResponder];
[self.rootController.changeClientViewController.searchDisplayController setActive:YES];

The keyboard pops up, like it should, but the lines in between each table cell are white, instead of dark-grey, and it looks bad. I am using the same code in another place to automatically pop up the keyboard; and there the lines are dark-grey as expected. Has anyone come across this? I could link to a screenshot if it would be helpful...

GendoIkari
  • 11,734
  • 6
  • 62
  • 104
  • Is this in `viewWillAppear:`, `viewDidAppear:` or something else? – bosmacs Dec 06 '10 at 22:34
  • It's in a separate controller (thus the long path to get to the searchBar)... We tried it in `viewDidLoad`, `viewDidAppear:`, and `viewWillAppear:` first, but it wasn't bringing up the keyboard at all then. (Although in the controller where it's working fine, it's in `viewWillAppear:`) The only difference I can see is that the one that works is a full-screen modal view; while this is just a subview. – GendoIkari Dec 06 '10 at 22:39

1 Answers1

2

Here's one way to fix it: becomeFirstResponder after a minuscule delay, i.e.

[self.rootController.changeClientViewController.searchDisplayController.searchBar
    performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.0];
bosmacs
  • 7,341
  • 4
  • 31
  • 31
  • Ok, this basically worked... I also had to get rid of the `setActive:`, then it worked... Any chance you could explain 1) How can a delay of 0.0 do anything at all? There's 0 delay. 2) The other place in code where I do this requires `setActive:` to work properly. The keyboard doesn't come up if I don't have it. Whereas here, I have to get rid of `setActive:` to make it work properly?? – GendoIkari Dec 07 '10 at 16:19
  • I believe `becomeFirstResponder` effectively makes the search controller active. As for the 0.0 delay, even though it's 0.0 it does not execute immediately, but schedules a timer that will be evaluated on the default run loop. See this answer for more information: http://stackoverflow.com/questions/1922517/how-does-performselectorwithobjectafterdelay-work – bosmacs Dec 07 '10 at 18:37
  • Well I'm still a bit lost as to why I had to do setActive: in one place; but had to not use setActive: in another place.... but as your response did lead me to a place where my code works as wanted, I'll accept. – GendoIkari Dec 07 '10 at 21:40
  • I needed a delay of 0.001 (iOS 5.0 in simulator). I'm using RubyMotion though. – dentarg Jan 22 '13 at 16:48