UISearchBar Disappears After Events

I have a UISearchBar in my view contained inside a UITableView above the top-most cell. Everything works fine until I push a new view controller onto the navigation stack. Once I pop the new VC and return to the original view controller the search bar does not show atop the table. Instead there is a white space between my navigation bar and the top row of my table view. However, if I click this white space then the search bar opens as if it were there normally, and when I click cancel again all is well.

I think that somehow the view for the UISearchBar is being set to be entirely white, but I have no idea why. I originally have the UISearchBar just added into the storyboard, as part of a UISearchDisplayController. How can I prevent the search bar from going white after my VC is unwound to from another controller than was pushed onto the navigation stack?


I have the same problem. I don't think it relates to the color of the search bar but to the layout of the search bar's subviews. After many trials and errors I came up with this solution:

@interface MySearchBar : UISearchBar
@end

@implementation MySearchBar

-(void) layoutSubviews
{
    [super layoutSubviews];
    if (self.subviews.count == 1)
    {
        UIView *subview = [self.subviews objectAtIndex:0];
        subview.frame = self.bounds;
    }
}

@end

Use MySearchBar instead of UISearchBar

链接地址: http://www.djcxy.com/p/55970.html

上一篇: 如何使UIView作为UISearchBar隐藏在UITableView中

下一篇: 事件后UISearchBar消失