2012-02-08 114 views
4
  • 我有一个UITable,它有一个UISearchDisplayController
  • UITable小于屏幕宽度(宽度居中280px)。
  • 当我在search bar挖掘中,UISearchDisplayController表是一路在屏幕的左侧。
  • 改变UISearchDisplayController的表框即使,我仍然得到同样的定位。

我在这里设置的帧:iOS中的UITableView的UISearchDisplayController框架

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView { 
    tableView.backgroundColor = [UIColor colorWithRed:29.0/255.0 green:30.0/255.0 blue:32.0/255.0 alpha:1]; 
    tableView.rowHeight = self.myTable.rowHeight; 
    tableView.frame = myTable.frame; 
    NSLog(@"search table origin: %f",tableView.frame.origin.x); 
} 

即使怪异,当我登录搜索表位置在端部,它显示16。然而,它是在视图位置0。

任何帮助表示赞赏。

+0

这从汤姆·斯威夫特的回答解决我的问题:http://stackoverflow.com/a/4128659/ 675486 – 2012-08-02 14:07:05

回答

20

我回答了我自己的问题。该框架需要此委托方法进行设置:

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { 

    tableView.frame = self.myTable.frame; 

} 
+0

谢谢,我刚刚创建了自己的表格视图,因为我想将它移动到搜索栏的下方,无法找到干净的方法来完成它。 – 2012-09-26 14:34:03

+1

谢谢,它帮助我,但至少留下了2个问题:旋转设备时,条适合整个屏幕宽度,关闭动画时很丑,它再次闪烁到整个宽度。 – Tom 2014-02-10 20:48:09

1

试试这个简单的方法:

//--Search display controller frame 

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView 
{ 
    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; 

    [tableView setFrame:CGRectMake(my_table.frame.origin.x, tableView.frame.origin.y, my_table.frame.size.width, my_table.frame.size.height)]; 

}