iphone - 无法从自定义单元格重新加载 Tableview

标签 iphone ios objective-c ipad uitableview

我有一个带有自定义 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/

相关文章:

iphone - 使用 SQLCipher 将加密数据库附加到未加密数据库

iphone - Facebook API - 屏幕出现安全警告 : Please treat the URL above as you

iphone - 在运行时添加标志(Xcode Instruments)

ios - 按姓氏分组的 Core Data 家族成员

ios - 如何在 XR 手机上调整圆圈大小/修复约束

ios - 无法从 Sprite Kit 打开 Game Center

iPhone iOs 5,根据内容高度动态更改滚动查看器的高度不起作用?

ios - 如何在 UITableView 的编辑模式下启用滑动删除和删除按钮

iOS:如何使用 constraintsWithVisualFormat 设置尾随边距?

android - 使用 AS3 在 iPhone 和 android 中设置提醒