ios - UITableView 禁用用户不可见的行

标签 ios objective-c uitableview

我有一个自定义的 UITableView(990x580 像素),其中表格的每个单元格内都有一个文本字段,文本字段由标签区分:

cell.myTextField.tag = indexPath.row;

假设我的表格中有 20 行,导致我看到表格的所有行将不得不使用滚动(因为表格只有 990x598 像素)

假设我们正在查找表格的第 20 行,并且第 1 行不再可见(除非我使用滚动向上),我想知道为什么当我尝试获取现有信息时在标签等于 1 的文本字段中,应用程序没有返回任何内容?

我意识到,当这个文本字段对用户不可见时,它似乎被禁用了,想找到一种方法让它不翻转用户不可用的行,这是我的表格 View 如下:

- (UITableViewCell *)tableView:(UITableView *)tableView2 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{//Ja explicado anteriormente

    static NSString *simpleTableIdentifier = @"ComissoesTableViewCell";//Ja explicado anteriormente

    ComissoesTableViewCell *cell = (ComissoesTableViewCell *)[tableView2 dequeueReusableCellWithIdentifier:simpleTableIdentifier];//Ja explicado anteriormente

    if (cell == nil){//Ja explicado anteriormente

        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ComissoesTableViewCell" owner:self options:nil];//Ja explicado anteriormente
        cell = [nib objectAtIndex:0];//Ja explicado anteriormente
    }
    cell.data.tag = indexPath.row;
    return cell:

}

最佳答案

UITableView 的工作原理是在单元格滚动出表格的可见部分时自动重复使用这些单元格。这使得单元格信息在您再次配置重用单元格时重置。

您需要在 viewController 级别存储持久化信息(例如,在 NSArrayNSDictionary 中)。考虑使用 NSDictionary 并存储由单元格的 indexPath 索引的单元格内容 NSString


还要注意以下几点

if (cell == nil){//Ja explicado anteriormente

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ComissoesTableViewCell" owner:self options:nil];//Ja explicado anteriormente
    cell = [nib objectAtIndex:0];//Ja explicado anteriormente
}

不再推荐。

如果您为 simpleTableIdentifier 注册了一个 nib 或类(例如,使用 - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier)保证 deque 方法永远不会返回 nil,因为它会根据需要自动创建新的单元格。

关于ios - UITableView 禁用用户不可见的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24770070/

相关文章:

ios - 如何在 iOS 应用程序中包含 github 项目,就像 android studio 中的依赖项一样

ios - 触摸移动方法中物理体尺寸不随 SKSpriteNode 尺寸变化而变化

ios - 如何将 UITableViewCell 显示为选中状态并仍然接收 didDeselectRowAtIndexPath

iphone - 无法呈现 modalViewController

swift - 打字时扩大 uitableview 单元格高度并避免键盘

iphone - 处理IOS应用程序开发中的中断

ios - 当授权应用程序时,Facebook iOS SDK不调用完成处理程序

ios - 如何在TableView中显示两个自定义单元格?

ios - 没有 Storyboard的自定义 UITableViewCell 不显示

ios - glGetRenderbufferParameterivOES 返回错误的大小