0

我目前正在尝试在弹出框内放置一个表格视图和搜索栏,但我遇到了一个非常奇怪的错误。每当我点击搜索栏时,取消按钮就会出现动画,并且栏会立即降低到状态栏的大小。

正常状态

选择时

我试过玩 UIBarPosition 委托,但这也无济于事。我已经尝试了几乎所有我能想到的东西,所以我想我会寻求你的帮助。这是我在 UITableViewController 中用于将搜索栏添加到表头的代码:

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];

if (self)
{

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, popoverWidth, singleRowHeight)];
    searchBar.delegate = self;
    searchBar.showsScopeBar= YES;

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;
    searchDisplayController.searchResultsDelegate = self;
    searchDisplayController.searchResultsTableView.rowHeight = singleRowHeight;
    self.automaticallyAdjustsScrollViewInsets = NO;

    self.tableView.tableHeaderView = searchBar;

    return self;
}

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
    return UIBarPositionTop;
}

谢谢!

4

1 回答 1

2

根据UISearchDisplayController 处于活动状态时搜索栏上方的额外空间

- (void)viewDidLoad {
   [super viewDidLoad];

    if ([self respondsToSelector:@selector(edgesForExtendedLayout:)]) { /// iOS 7 or above
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
}
于 2013-11-10T08:43:19.640 回答