相关疑难解决方法(0)

在默认搜索栏中搜索字符串为空时启用搜索按钮

在我的应用程序中我使用默认IOS搜索栏的搜索功能,如果我放置一些字符串进行搜索工作正常但在第一次搜索后我需要显示整个数据源(原始内容.)我的功能是如果搜索字符串是为空它将显示整个数据源.我的问题是如果我在默认搜索栏中将搜索字符串设为空,搜索按钮会自动进入隐藏状态.我需要启用搜索按钮,即使字符串是空的.请指导我解决此问题.

在此输入图像描述

谢谢.

iphone objective-c uisearchbar ios

24
推荐指数
2
解决办法
2万
查看次数

iphone UISearchBar完成按钮始终启用

我有一个带UISearchBar的UIViewController.我已通过完成按钮替换了搜索按钮.

但是,当单击搜索栏时,最初会禁用"完成"按钮.这会发生,直到一个人输入任何字符

我想要做的是始终启用此完成按钮,这样如果我点击它我可以立即关闭键盘.

有帮助吗?非常感谢.

我有我的UIViewController

-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar  
{   
    return YES;  
}  

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
}  

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText  
{  
    if (searchBar.text.length == 0)  
    {  
        //[self fixOrientation];  
        [searchBar resignFirstResponder];  
    }   
    else  
    {  
        NSLog(@"typed");  
    }  
}  


-(void)searchBarTextDidBeginEditing:(UISearchBar *)theSearchBar  
{  
    NSLog(@"began");  // this executes as soon as i tap on the searchbar, so I'm guessing this is the place to put whatever solution is available  
}  
Run Code Online (Sandbox Code Playgroud)

iphone keyboard uisearchbar first-responder

20
推荐指数
4
解决办法
2万
查看次数