相关疑难解决方法(0)

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万
查看次数

标签 统计

first-responder ×1

iphone ×1

keyboard ×1

uisearchbar ×1