Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在iOS中切换搜索栏_Objective C_Ios_Cocoa Touch_Animation_Searchbar - Fatal编程技术网

Objective c 在iOS中切换搜索栏

Objective c 在iOS中切换搜索栏,objective-c,ios,cocoa-touch,animation,searchbar,Objective C,Ios,Cocoa Touch,Animation,Searchbar,我有一个TableView,底部有一个搜索按钮。我希望“搜索”按钮能在顶部弹出一个搜索栏,使其成为焦点。否则,不应显示搜索栏 在表视图上方放置搜索栏很容易,但是有没有办法用动画隐藏/显示它 谢谢。您是否尝试过使用-[UITableView scrollRectToVisible:animated:][/code>方法?我认为UISearchBar视图通常只是表上的标题视图,因此您应该能够要求表视图向上滚动以显示搜索栏。您是否尝试过使用-[UITableView scrollRectToVisib

我有一个
TableView
,底部有一个搜索按钮。我希望“搜索”按钮能在顶部弹出一个
搜索栏
,使其成为焦点。否则,不应显示
搜索栏

表视图上方放置搜索栏很容易,但是有没有办法用动画隐藏/显示它


谢谢。

您是否尝试过使用
-[UITableView scrollRectToVisible:animated:][/code>方法?我认为
UISearchBar
视图通常只是表上的标题视图,因此您应该能够要求表视图向上滚动以显示搜索栏。

您是否尝试过使用
-[UITableView scrollRectToVisible:animated:
方法?我认为
UISearchBar
视图通常只是表上的标题视图,因此您应该能够要求表视图向上滚动以显示搜索栏。

这对我很有用。希望能有帮助

在视图中调用[self hideSearchBar]将出现(这将最初隐藏搜索栏)

您的搜索按钮应具有以下操作:

- (IBAction)searchIconButtonClicked {
    if (self.searchDisplayController.isActive || (self.tableView.contentOffset.y < 44)) {
        if (self.searchDisplayController.isActive) {
            self.searchDisplayController.searchBar.text = nil;
            [self.searchDisplayController setActive:NO animated:YES];
            [tableView reloadData];
        }
        [self hideSearchBar];
    } else {
        [self.patientTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
    }
}

- (void)hideSearchBar {
    //NSLog(@"Hiding SearchBar");        
    [self.tableView setContentOffset:CGPointMake(0,44)];
}
-(iAction)搜索图标按钮单击{
if(self.searchDisplayController.isActive | |(self.tableView.contentOffset.y<44)){
if(self.searchDisplayController.isActive){
self.searchDisplayController.searchBar.text=nil;
[self.searchDisplayController设置活动:否动画:是];
[tableView重新加载数据];
}
[自我隐藏搜索栏];
}否则{
[self.patientTableView scrollRectToVisible:CGRectMake(0,0,1,1)动画:是];
}
}
-(无效)隐藏搜索栏{
//NSLog(@“隐藏搜索栏”);
[self.tableView setContentOffset:CGPointMake(0,44)];
}

这对我很有用。希望能有帮助

在视图中调用[self hideSearchBar]将出现(这将最初隐藏搜索栏)

您的搜索按钮应具有以下操作:

- (IBAction)searchIconButtonClicked {
    if (self.searchDisplayController.isActive || (self.tableView.contentOffset.y < 44)) {
        if (self.searchDisplayController.isActive) {
            self.searchDisplayController.searchBar.text = nil;
            [self.searchDisplayController setActive:NO animated:YES];
            [tableView reloadData];
        }
        [self hideSearchBar];
    } else {
        [self.patientTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
    }
}

- (void)hideSearchBar {
    //NSLog(@"Hiding SearchBar");        
    [self.tableView setContentOffset:CGPointMake(0,44)];
}
-(iAction)搜索图标按钮单击{
if(self.searchDisplayController.isActive | |(self.tableView.contentOffset.y<44)){
if(self.searchDisplayController.isActive){
self.searchDisplayController.searchBar.text=nil;
[self.searchDisplayController设置活动:否动画:是];
[tableView重新加载数据];
}
[自我隐藏搜索栏];
}否则{
[self.patientTableView scrollRectToVisible:CGRectMake(0,0,1,1)动画:是];
}
}
-(无效)隐藏搜索栏{
//NSLog(@“隐藏搜索栏”);
[self.tableView setContentOffset:CGPointMake(0,44)];
}

有效,但搜索栏在默认情况下仍然可见,因为它必须被指定为
tableView.tableHeaderView
。而且,它有点笨重,因为tableview必须一直滚动到顶部才能访问
UISearchBar
。我正在寻找一种显示no
UISearchbar
的方法,直到点击搜索按钮。目前,一个
UISearchDisplayController
很接近我想要的,尽管它最初仍然没有隐藏
UISearchBar
。这是可行的,但是搜索栏在默认情况下仍然可见,因为它必须被指定为
tableView.tableHeaderView
。而且,它有点笨重,因为tableview必须一直滚动到顶部才能访问
UISearchBar
。我正在寻找一种显示no
UISearchbar
的方法,直到点击搜索按钮。目前,一个
UISearchDisplayController
接近我想要的,尽管它最初仍然没有隐藏
UISearchBar