iphone - How to dismiss the Keyboard using UIsearchBar Delegate methods? i tried every method but no use. -


hi using uisearchbar in app, tried methods in uisearchbar delegate dismiss keyboard no use. me out.

some codes tried

1.

-(void)searchbartextdidendediting:(uisearchbar *)searchbar {     [searchbar resignfirstresponder]; } 

2.

-(bool) searchbar:(uisearchbar *)searchbar shouldchangetextinrange:(nsrange)range replacementtext:(nsstring *)text {      if([text isequaltostring:@"\n"])     {         [searchbar resignfirstresponder];         return no;     }     return yes;  } 

3.

- (void)searchbarcancelbuttonclicked:(uisearchbar *) searchbar {      [searchbar resignfirstresponder]; } 

first of should implement uisearchbardelegate in class & check if have connected uisearchbar or not?

if adding uisearchbar through ib should select delegate property of uisearchbar file's owner. should make sure connecting iboutlet uisearchbar in code .

if adding uisearchbar via code should set delegate in code searchbar.delegate=self;

next step make sure delegate methods being called, obvious if have connected delegate properly, best thing check stuff putting break pointer in code or print through nslog.

finally use method hide keyboard if want hide when user clicks search

- (void) searchbarsearchbuttonclicked:(uisearchbar *)searchbar {     [searchbar resignfirstresponder]; } 

or try when editing finished

- (void)searchbartextdidendediting:(uisearchbar *)searchbar {     [searchbar resignfirstresponder]; } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -