Search code examples
iosiphoneuisearchbaruisearchdisplaycontroller

Overlay area stays on top after searching a list UIView


I have a UIView with a list of items. When I click the search bar the keyboard comes up and the rest of the screen contains a grey overlay.

enter image description here

When I click on the grey overlay the keyboard disappears, however the overlay area stays on top and is not disappearing. What is the root of cause of this problem? How can I resolve it?


Solution

  • Check it:-

    Write this in console:- by giving breakpoint in the view controller

     po [self.view subviews]
    
    (id) $1 = 0x0a3155f0 <__NSArrayM 0xa3155f0>(
    <ATShadowTableView: 0xc341600; baseClass = UITableView; frame = (0 44; 320 411); clipsToBounds = YES; gestureRecognizers = <NSArray: 0xa627200>; layer = <CALayer: 0xa626d30>; contentOffset: {0, 0}>,
    <UISearchBar: 0xa618f40; frame = (0 0; 320 44); text = ''; layer = <CALayer: 0xa619040>>,
    <UIControl: 0xa329fc0; frame = (0 44; 320 455); alpha = 0.8; opaque = NO; animations = { opacity=<CABasicAnimation: 0xa32b4e0>; }; layer = <CALayer: 0xa32a060>>
    )
    

    Last object (UIControl) in self.subview is what we want to remove. So

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
    {
    ...
        [self performSelector:@selector(removeOverlay) withObject:nil afterDelay:.01f];
    }
    
    - (void)removeOverlay
    {
        [[self.view.subviews lastObject] removeFromSuperview];
    }