ios - 无法在 searchBar 方法中更改 UITableView 框架

标签 ios uitableview

我有一个完全被 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/

相关文章:

iphone - iPhone 中新联系人表单中的预填充字段和完成按钮将保存联系人

ios - Iphone 删除 subview

ios - 即使更新了表格 View 单元格,如何在表格 View 中保留表格 View 单元格的编辑模式?

Ios Facebook SDK 我如何分享图片、链接、文本?

ios - React原生私有(private)部署

iphone - 如何在iOS中实现类似安卓手机(默认)的裁剪功能?

ios - View 标签属性的 switch 语句

ios - 选择文本字段时使 UITableView 滚动

ios - uitableview 根本没有显示

ios - 搜索 CoreData 以匹配 NSDate - Swift