【问题标题】:iOS Table View Refresh CelliOS 表格视图刷新单元格
【发布时间】:2012-05-12 00:54:22
【问题描述】:

我按照下面链接中的建议将图像添加到表格视图中的单元格。

Adding Image to Table Cell (iOS)

有没有办法强制刷新单元格,即添加/删除图像或指示器?

【问题讨论】:

    标签: ios iphone objective-c uitableview


    【解决方案1】:

    你可以在tableview上调用[self.tableview reloadData];,刷新整个表格。

    否则,您可以这样做来刷新单个单元格。

     [self.tableView beginUpdates];
     [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPathOfYourCell] withRowAnimation:UITableViewRowAnimationNone];
     [self.tableView endUpdates];
    

    【讨论】:

    • 我试过 [self.tableview reloadData] 除了它似乎不记得方法“- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath”并添加图像到新单元格。
    • 放一个 NSLog(@"Method called");如果您想向自己证明这一点,请在您的- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 中。
    【解决方案2】:

    由于您已经拥有单元格的 indexPath,因此有时这可能只是工作

    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    [cell reloadInputViews];
    

    【讨论】:

    • 如果您只是使用 UITableViewCell 而不是自定义类,则不需要将 UITableViewCell 指针转换为 UITableViewCell 指针
    【解决方案3】:

    您可以调用UITableView 类的reloadRows(at:with:) 方法,使用给定的动画效果重新加载UITableView 实例的某些行。

    请注意,如果您想在 UITableView 实例中插入或删除某些行,则有类似命名的 insertRows(at:with:)deleteRows(at:with:) 方法。

    【讨论】:

      猜你喜欢
      • 2015-03-07
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      相关资源
      最近更新 更多