UISearchDisplayController frame for UITableView in iOS

  • I have a UITable that has a UISearchDisplayController .
  • UITable less than the width of the screen (it is centered across a width of 280 pixels).
  • When I click on the search bar , the UISearchDisplayController table is completely to the left of the screen.
  • Even when changing the frame of the UISearchDisplayController table, I still get the same positioning.

I set the frame here:

 - (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); } 

Even stranger, when I write the position of the lookup table at the end, it shows 16. However, it is at position 0 in the view.

Any help is appreciated.

+4
source share
2 answers

I answered my question. The frame must be set in this delegate method:

 - (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { tableView.frame = self.myTable.frame; } 
+20
source

Try this simple method:

 //--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)]; } 
+1
source

Source: https://habr.com/ru/post/1395469/


All Articles