Search code examples
iosiphoneobjective-cios7ipod

Scroll and add Search Bar asynchronously


I have this application in which I have a right bar button item which adds the search bar as title view. This works fine but when the table view is scrolling, this doesn't happen. It only adds when the table view has stopped scrolling.

Any way to handle this?


Solution

  • The main thread does not responds to events if its busy, use GCD to add this to Queue

    Check if this function is called while scrolling. If yes , then simply using GCD will solve your problem.

    -(void)userTapOnRightBarButton{
        NSLog(@"Main thread response to touch during scrolling"):
        dispatch_async(dispatch_get_main_queue(), ^{
               [self addSearchBar];
       });
    }