Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchBar - ReturnKeyType not working for iOS 8

I am using UISearchbar in tableview controller in storyboard. And searchbar returnKeyType is UIReturnKeySearch.

enter image description here

Its working fine with iOS7 but returnKeyType is not working with iOS8. in iOS8, return key appears every time in keyboard. I tried to set returnkeytype in viewDidLoad method of controller too. What I need to do to set returnKeyType = UIReturnKeySearch in iOS8?

like image 370
Pradip Vanparia Avatar asked Nov 23 '22 01:11

Pradip Vanparia


2 Answers

I think you can go with your hard codded logic for right now. I will update if I will get better solution for your problem.

-(void)viewDidLoad {
    [self setReturnKeyTypeSearchForView:searchBar];
}

-(void)setReturnKeyTypeSearchForView:(UIView *)view
{
    for (id subView in view.subviews) {
        if ([subView isKindOfClass:[UITextField class]]) {
            [subView setReturnKeyType:UIReturnKeySearch];
        }
        else {
            [self setReturnKeyTypeSearchForView:subView];
        }
    }
    if ([view isKindOfClass:[UITextField class]]) {
        [(UITextField *)view setReturnKeyType:UIReturnKeySearch];
    }
}
like image 90
ObjC Avatar answered Dec 08 '22 21:12

ObjC


Try making IBOutlet of your SearchBar

@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;

and add the below line code to your viewDidLoad Method

 // if u want Done return key and change accordingly.
_searchBar.returnKeyType = UIReturnKeyDone;
like image 30
Dheeraj Singh Avatar answered Dec 08 '22 21:12

Dheeraj Singh