Hiding keyboard iphone sdk?

Deadly 提交于 2019-12-12 05:13:21

问题


I have a UISearchBar. I want the the keyboard to go away as soon as user hits search...i did try resignFirstResponder but that didn't work. any help would be appreciated

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = NSLocalizedString(@"Songs", @"Search for songs");


    NSMutableArray *array = [[NSArray alloc]initWithObjects: @"Book_1", @"Book 2", @"Book _ 4", nil];
    self.booksArray = array;
    [array release];
    search.delegate=self;
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

thanks TC


回答1:


Please make sure of following things.(I hope you are talking about search Button of keyboard.)

  1. You have connected your IBOutlet of searchBar with its variable search.
  2. You are not de-referring search variable anywhere in your code(reassigning it).
  3. Your - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar method is in same viewcontroller as searchBar is in.
  4. Please NSLog(@"Search Bar Instace : %@",search); in viewDidLoad method and searchBarSearchButtonClicked and verify that both instances are same if not then you are search is getting reassigned somewhere in code.
  5. Just after [searchBar resignFirstResponder]; NSLog(@"isFirstResponder : %d",[searchbar isFirstResponder]); and NSLog(@"Next Responder : %@",[searchBar nextResponder]);
  6. Is - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar method is being called when you tap search Button of keyboard? Make sure there are no keyboard responder(like textField,textView or other searchBar) is added behind your searchBar may be unintentionally. Please check it through xib also.

Thanks,




回答2:


It should work by implementing the respond methods at the delegate object:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
}

Reference: http://www.iphonedevsdk.com/forum/iphone-sdk-development/7148-problem-uisearchbar-navigation-controller.html#post59467



来源:https://stackoverflow.com/questions/5657361/hiding-keyboard-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!