Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C, how to Generally resignFirstResponder?

(my boss says) that I have to implement a "Done" button on a navBar so that the various items in the view (that contain an edit box) will dismiss their keyboard (if they were in focus).

It seems that I must iterate through all items and then call resignFirstResponder on each on the off-chance that one of them is in focus? This seems a bit messy (and hard to maintain if e.g. someone else adds more items in future) - is there a better way to do it?

like image 699
Robin Pain Avatar asked Sep 03 '10 10:09

Robin Pain


1 Answers

I have found it!

Thanks to this

I discovered that all I need do is this:-

-(void) done {
    [[self.tableView superview] endEditing:YES];
}

// also [self.view endEditing:YES]; works fine

[remark] Also I learn how to do the equivalent of an "eventFilter" to stop UITableViewController from swallowing background touch events by intercepting them before they get there - from the same, wonderful post on that thread - see "DismissableUITableView". [end of remark]

like image 179
Robin Pain Avatar answered Oct 14 '22 03:10

Robin Pain