ios - Make UISearchController search bar automatically active -
i've implemented uisearchcontroller search bar in navigatiom bar , make search bar active when view loaded. when active, mean keyboard appears , user can type his/her search without tap search bar.
i initialised uisearchcontroller following code:
- (void)viewdidload { self.searchcontroller = [[uisearchcontroller alloc] initwithsearchresultscontroller:nil]; [self.searchcontroller setsearchresultsupdater:self]; [self.searchcontroller setdimsbackgroundduringpresentation:no]; [self.searchcontroller sethidesnavigationbarduringpresentation:no]; [self.navigationitem settitleview:self.searchcontroller.searchbar]; [self setdefinespresentationcontext:yes]; [self.searchcontroller.searchbar setdelegate:self]; [self.searchcontroller.searchbar setshowscancelbutton:yes]; [self.searchcontroller.searchbar setplaceholder:@"city or airfield"]; [self.searchcontroller.searchbar sizetofit]; } i've tried make search controller active, call [self.searchcontroller.searchbar becomefirstresponder] , directly call searchbarsearchbuttonclicked nothing works.
try calling
[self.searchcontroller setactive:yes] before
[self.searchcontroller.searchbar becomefirstresponder] if above not working, try this:
- (void)viewdidload { [super viewdidload]; ... [self initializesearchcontroller]; .... } - (void)viewdidappear:(bool)animated { [super viewdidappear:animated]; [self.searchcontroller setactive:yes]; [self.searchcontroller.searchbar becomefirstresponder]; } - (void)initializesearchcontroller { self.searchcontroller = [[uisearchcontroller alloc] initwithsearchresultscontroller:nil]; self.searchcontroller.searchresultsupdater = self; self.searchcontroller.dimsbackgroundduringpresentation = no; self.searchcontroller.delegate = self; self.searchcontroller.searchbar.delegate = self; [self.searchcontroller.searchbar sizetofit]; [self.tableview settableheaderview:self.searchcontroller.searchbar]; self.definespresentationcontext = yes; }
Comments
Post a Comment