I've put some UITextViews in a UITableView(Controller) with custom cells, and I'm running into a problem. The user can hit the "Edit" button up in the navbar to set the table int开发者_C百科o editing mode - each custom cell has its own way of enabling its individual UITextViews for text entry. That works fine.
The problem I'm having is that if focus is on a text view that gets scrolled out of view when the user hits "Done", the keyboard remains and the textview remains in edit mode. This doesn't happen if the textview is in view. More specifically - the cell i'm looking at is at the top of the screen and will act funny if it's scrolled above the iPhone screen. I don't seem to have the same problem when the textview at the bottom of the table gets scrolled out.
I've done just about every single permutation I could think of to get the view to resign first responder, but it appears to me that the hidden textview doesn't get/send any messages (even any delegate methods) until it is back on to the screen OR some other text view gets focus.
What am I missing?
After working on this for the better part of a full day, this is what I learned:
- You can't actually access out-of-view cells in UITableView. I guess that makes sense, though frustrating in my situation
- No amount of redrawing or trying to manually resign first responder is going to help, even when you point to a specific cell in a specific row.
- setEditing: animated: (called when you hit the "Done" button) isn't the only thing going on
- I'm going to guess that the reason the UITextView remains in edit mode is because the cached version of the cell is in edit mode and cached cells/data aren't called by these various table methods (like setEditing:animated:)
This is the solution I found: (at UISearchBar and resignFirstResponder):
* calling [self.tableView endEditing:YES]
causes all views to resign first responder, which means my UITextView is no longer selected. I'm not sure why it works this way, but appears setEditing: is sent to each cell & redrawn accordingly.
精彩评论