"静态" UISearchBar将它的边距扩展到UITableView

时间:2015-05-30 11:16:36

标签: ios uitableview uisearchbar

我的UISearchBar上有一个UITableView,这里的布局如下: enter image description here

请注意,我不会UISearchBar在搜索时隐藏UINavigationBar

当我开始搜索UISearchBar时,将其边距延伸到UITableView。这是2个州的预览: enter image description here

以下是视频预览:https://dl.dropboxusercontent.com/u/14522796/SearchBarExtends2.mov

问题是:为什么会发生这种情况以及如何防止这种情况发生? 感谢。

1 个答案:

答案 0 :(得分:0)

试试这个。

          UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 300, 44.0)];
      searchBar.autoresizingMask =0;
       searchBar.delegate = self;
       searchBar.placeholder = @"Search for items...";
        searchBar.showsScopeBar=YES;

   UIView *searchBarWrapper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
searchBarWrapper.autoresizingMask = 0;
[searchBarWrapper addSubview:searchBar];



[searchbar  sizeToFit]; //[searchbar= your objectname]