Removing the keyboard after selecting a customer's name
To remove the keyboard when any customer name is selected from the table view, we need to use the tableView:willSelectRowAtIndexPath:
method. In this method, we inform the Search Bar to resign the first responder's status, which will cause the keyboard to go away and return the indexPath
, as shown next:
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[srchbar resignFirstResponder];
return indexPath;
}
We can also do the same by using tableView:didSelectRowAtIndexPath:
method. On implementing the preceding method in the implementation file: RootViewController.m
, we find that the keyboard goes away on selecting any customer's name from the table view.
Let us run the project to see the searching facility implemented by us. So, select the Build and Run icon from the Xcode Project window. Initially, the Search Bar is empty and hence the whole list of customer names will be displayed in...