1)searchBar动态显示/隐藏按钮 Cancel按钮
barBtn.showsCancelButton = YES;//显示
barBtn.showsCancelButton = NO;//隐藏
2)输入内容点击搜索后,searchBar失去焦点,键盘不消失且Cancel按钮的颜色变成了灰色(连续两次点击搜索键盘才消失 但是Cancel按钮的颜色还是灰色)
解决方法:searchBarSearchButtonClicked内设置
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder]; //searchBar失去焦点
UIButton *cancelBtn = [searchBar valueForKey:@"cancelButton"]; //首先取出cancelBtn
cancelBtn.enabled = YES; //把enabled设置为yes
}
网友评论