iphone - 在 UITableView reloadData 之后在 UITextView 中设置选择?

标签 iphone ios objective-c uitableview

我在 UITableViewCell 中放置了一个 UITextView。一旦用户点击某个按钮,我将调用 [UITableView relodaData] 来更新 UITextView 中的内容。

我的目标是在调用 reloadData 后在 UITextView 中设置选择。是否有任何回调方法可用于 [UITableView reloadData] 方法,就像 performBatchUpdates 可用于 UICollectionView

最佳答案

重新加载 TableView 通常不会退出第一响应者。必须是您代码中的内容,例如 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 = ...;

关于iphone - 在 UITableView reloadData 之后在 UITextView 中设置选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18629145/

相关文章:

iphone - 如何找到天数

ios - 如何在iOS中集成mobileiron sdk

iphone - 使用 AFJSONRequestOperation 返回 JSON

objective-c - 在 UIWebView 中显示网页

iphone - Points对UIImage的透视校正

iphone - 使用 Storyboard在两个 Controller 之间传递数据

iphone - 视网膜显示和 [UIImage initWithData]

ios - 快速写入文件

ios - 将彩色 UIImageView 添加到 UITableViewCell 时的奇怪行为

objective-c - CMTime 秒输出