I'm attempting to set the UITextViews in a set of UITableViewCell's to editable when the user taps the "edit" button for the UITableView. Each UITableViewCell has a UITextField (cell.blurb). This code will set each UITextView to editable, however, the cursor alternates very rapidly between each one. I'm pretty sure it's a responder chain issue, (they're all becoming first responders maybe?) however I can't seem to remedy it. I've tried having each UITextView resignFirstResponder (save for the first one in the list), but it does nothing. In the table cell xib they're uneditable.
//set all text areas to editable and opaque
int numSections = [_tableView numberOfSections];
for (int s = 0; s < numSections; s++) {
int numRows = [_tableView numberOfRowsInSection: s];
for (int r = 0开发者_开发技巧; r < numRows; r++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:r inSection:s];
CustomTableViewCell *cell = (CustomTableViewCell *)[_tableView cellForRowAtIndexPath:indexPath];
[cell blurb].editable = YES;
[[cell blurb] resignFirstResponder];
//set the first row's UITableView to the first responder
if (s == 0 && r == 0)
[[cell blurb] becomeFirstResponder];
}
}
The only solution I managed to make work is create two UITextViews, one editable, one not with the same frame and properties, and manage opacity of each according to editable state. Quite lame isn't it ?
Another thing, I had to implement this in my delegate (which happens to be the UITableViewCell subclass):
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
if (!self.editing)
return NO;
return YES;
}
otherwise, for an unknown reason, the end of the UITableView animation (when it quits editing mode) triggers again becomeFirstResponder on one of the UITextView.
Here is a thread on devforums https://devforums.apple.com/message/290194
if (s == 0 && r == 0) {
[[cell blurb] becomeFirstResponder];
} else if ([[cell blurb] isFirstResponder]) {
[[cell blurb] resignFirstResponder];
}
精彩评论