我有一个完全被 UINavigationBar 和 UITableView 占据的 View Controller 。当用户点击 UITableView 中的搜索栏时,我想隐藏导航栏并让表格 View 完全占据屏幕。这是我的代码:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"typing text");
navBar.hidden = YES;
[tableview setFrame:CGRectMake(0, 20, 320, 568)];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
NSLog(@"clearing text");
navBar.hidden = NO;
[tableview setFrame:CGRectMake(0, 64, 320, 504)];
}
但是,外观/框架更改代码不起作用。另一方面,我知道这些方法被调用是因为 NSLogs 出现了。谁能提供任何解决方案?
最佳答案
试试这个:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"typing text");
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.tableView setFrame:CGRectMake(0, 20, 320, 568)];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
NSLog(@"clearing text");
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.tableView setFrame:CGRectMake(0, 64, 320, 504)];
}
添加动画标志可以解决问题。希望这对您有所帮助!
关于ios - 无法在 searchBar 方法中更改 UITableView 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23895513/