Custom InputView for UISearchBar doesn't work after tap cancel button in iOS7 -
in ios app , need set custom inputview
uisearchbar
in ios7
.
so wrote following codes.
nsarray *searchbarsubviews = [[self.sbar.subviews objectatindex:0] subviews]; for(int =0; i<[searchbarsubviews count]; i++) { if([[searchbarsubviews objectatindex:i] iskindofclass:[uitextfield class]]) { uitextfield* search=(uitextfield*)[searchbarsubviews objectatindex:i]; [search setfont:[uifont fontwithname:@"customfont" size:15]]; search.delegate = self; [search setinputview:self.customkeyboard]; [self.customkeyboard settextview:search]; } }
it working fine. when type custom keyboard , tap cancel button resignfirstresponder
.
and tap uisearchbar
again, can't type text in uisearchbar
, including native english keyboard.
and cancel button hiding , uisearchbar
not working anymore.
i don't know why happening?
how can solve it?
i tried code , it's working fine app. in fact , congratulations seem in order, because 1 reason or other seem have solved problem others on site had built more elaborate workarounds for.
in app keyboard changes according selected scope of searchbar:
- scope == 0 presents customkeyboard
- scope != 0 presents usual iphone keyboard.
my implementation of code looks this:
-(uitextfield *)textfieldformsearchbar{ nsarray *searchbarsubviews = [[self.searchbar.subviews objectatindex:0] subviews]; for(int =0; i<[searchbarsubviews count]; i++) { if([[searchbarsubviews objectatindex:i] iskindofclass:[uitextfield class]]) { uitextfield* search=(uitextfield*)[searchbarsubviews objectatindex:i]; return search; } } return nil; } -(bool)searchbarshouldbeginediting:(uisearchbar *)searchbar{ if (searchbar.selectedscopebuttonindex==0) { self.textfieldformsearchbar.delegate = self; self.textfieldformsearchbar.inputview=self.customkeyboard; self.customkeyboard.field=self.textfieldformsearchbar; } else{ if (self.customkeyboard.superview!=nil) [self.customkeyboard removefromsuperview]; self.textfieldformsearchbar.delegate = self; self.textfieldformsearchbar.inputview=nil; self.customkeyboard.field=nil; } return yes; } -(void)searchbar:(uisearchbar *)searchbar selectedscopebuttonindexdidchange:(nsinteger)selectedscope{ if (selectedscope==0) { self.textfieldformsearchbar.delegate = self; self.textfieldformsearchbar.inputview=self.customkeyboard; self.customkeyboard.field=self.textfieldformsearchbar; } else{ if (self.customkeyboard.superview!=nil) [self.customkeyboard removefromsuperview]; self.textfieldformsearchbar.delegate = self; self.textfieldformsearchbar.inputview=nil; self.customkeyboard.field=nil; } [self.textfieldformsearchbar reloadinputviews]; } -(bool)searchbarshouldendediting:(hdlsearchbar *)searchbar{ if (self.customkeyboard) { [self.customkeyboard removefromsuperview]; } return [self.textfieldformsearchbar resignfirstresponder]; }
probably not efficient way it, trick. hope you'll find helps solve problem.
Comments
Post a Comment