2015-11-03 56 views
1

你好家伙我认为几乎所有在ios开发中的人都可能会遇到使用以下代码行重用UITableCell的问题。在ios中的UItableviewcell重用问题

RZRestaurantListingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

我有很多关于此的搜索,但没有得到任何愿望的答案,所以请帮助我在这种情况下。

我有同样的问题,因为大多数的iPhone开发者重新使用单元格后。 我有我的单元格内的UIProgressView和一个按钮是在那里下载视频,我显示进展中的进展视图剩下多少。 所以,现在我有什么问题是当我有更多的数据和当时的屏幕,我在UITableviewCell的第一行上按下载按钮,然后我滚动下来,所以进度也显示在底部随机一个单元格所以UI在两个单元中变化而不是一个。

+0

您不显示如何更新进度条,这可能是您的问题。您需要使用cellForRowAtIndexPath来查找要更新的进度条。不要在任何地方保留对单元格或进度条的引用。 – fishinear

回答

1

您需要在自定义单元类中实现-prepareForReuse方法,并将所有单元属性设置为默认值。

- (void)prepareForReuse 

如果一个UITableViewCell对象是可重复使用的,也就是说,它有一个再利用对象从UITableView的方法dequeueReusableCellWithIdentifier返回 之前 标识符调用此方法:.对于 性能原因,您应该只重置 与内容无关的单元格的属性,例如alpha,编辑和选择 状态。 tableView:cellForRowAtIndexPath: 中的表视图委托应该在重用单元时始终重置所有内容。如果单元格 对象没有关联的重用标识符,则此方法为 未调用。如果您重写此方法,则必须确保调用超类实现。

这里指的更多的,https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/#//apple_ref/occ/instm/UITableViewCell/prepareForReuse

+0

嘿vijay我已经实现了这种方法,但现在工作并重置我的细胞也在那里。 – jogshardik

+0

@jogshardik它工作还是不工作? – Vijay

+0

意思是我已经使用这种方法,但没有工作...之后,我已经在这里发布问题...让我再试一次 – jogshardik

0

使用prepareforreusemethodclear细胞的含量使用它......如前

-(void)prepareForReuse 
{ 
    [super prepareForReuse]; 

    self.textLabel.text = @""; 
    self.detailTextLabel.text = @""; 
    self.imageView.image = nil; 
} 
+0

让我再试一次 – jogshardik

0

您需要分配- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    RZRestaurantListingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // If the cell is reused, the `-prepareForReuse:` of `UITableViewCell` will be called. 

    //!! Assign current progress value to this cell, otherwise, the progressBar.value may look like a random value. 
    //!! Because the current cell is reused from a disappeared cell. 
    cell.progressBar.value = ... ; 

    return cell; 
} 

的设计可能是复杂的内部前进值,因为当单元格是屏幕上的进度可能会不断更新。

+0

我认为你是对的我需要在cellForRow中设置进度值 – jogshardik