我在UITextView
里面放了一个UITableViewCell
。一旦用户点击某个按钮,我将调用[UITableView relodaData]
来更新UITextView
.
我的目标是在UITextView
调用 reloadData 之后设置选择。是否有任何回调方法可用于[UITableView reloadData]
方法,就像performBatchUpdates
可用于
UICollectionView
.
我在UITextView
里面放了一个UITableViewCell
。一旦用户点击某个按钮,我将调用[UITableView relodaData]
来更新UITextView
.
我的目标是在UITextView
调用 reloadData 之后设置选择。是否有任何回调方法可用于[UITableView reloadData]
方法,就像performBatchUpdates
可用于
UICollectionView
.
重新加载表视图通常不会让第一响应者辞职。必须在您的代码中,例如在cellForRowAtIndexPath
.
无论如何,要恢复失去的焦点,跟踪哪个 textView 正在编辑(如果只有一个,那就更简单了),在调用之前记住它reloadData
并在之后恢复光标。
- (void)textViewDidBeginEditing:(UITextView *)textView {
_currentEditingTextView = textView;
}
- (void)textViewDidEndEditing:(UITextView *)textView {
_currentEditingTextView = nil;
}
- (void)yourUpdate {
UITextView *editingTextView = _currentEditingTextView;
[tableView reloadData];
[editingTextView performSelector:@selector(becomeFirstResponder)
withObject:nil
afterDelay:0.1]
}
此外,如果您只需要更新一个单元格,请通过reloadRowsAtIndexPaths
方法进行。或者,如果您只需要更新 textview 的文本,请直接执行此操作:
((YourCellClass *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:yourRow inSection:0]]).textView.text = ...;