我有一个带有自定义 tableview
单元格的 UITableView
。我的一个 Cell
有一个 UITextField
,我在自定义 tableviewCell
类中处理 textfield
委托(delegate)方法。我需要在用户输入文本后重新加载 tableview
,我已经做了下面的事情但没有用,任何想法请帮助我。
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
UITableView *parentTable = (UITableView *)self.superview;
[parentTable reloadData];
}
最佳答案
注册 View Controller 以接收数据已更改的通知,并在收到通知时刷新表。然后让解析器将其发送出去。
注册很容易:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadTableView:)
name:@"reloadTableView"
object:nil];
您的刷新方法需要设置为接收这些通知,如下所示:
- (void)reloadTableView:(NSNotification *)notif {
[self.yourTableName reloadData];
}
在您的 ViewDidUnload 中停止观察很重要:
[[NSNotificationCenter defaultCenter] removeObserver:self];
然后在解析器中,您需要在完成时简单地添加它:
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTableView"
object:nil];
View Controller (以及任何其他使用该名称观察通知的人)将获取消息并执行其任务。
谢谢..
关于iphone - 无法从自定义单元格重新加载 Tableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17335400/