滚动时表视图单元格不会重新加载

时间:2014-04-25 10:51:26

标签: objective-c uitableview

我有一个表格视图,其中设置了原型单元格,当视图首次加载我的标签的正确值时,为每个单元格正确填充滑块。当我向下/向上滚动时,屏幕上看不到的单元格似乎没有重新加载。它们具有空值。

我的数据源是一个可变数组(localArray)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LocalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

    cell.labelOutlet.text = [[localArray objectAtIndex:[indexPath row]] localChannel];
    cell.sliderOutlet.value = [[[localArray objectAtIndex:[indexPath row]] localPercentage] intValue];

    return cell;
}

登录

LOCAL CHANNEL: Webcast
LOCAL CHANNEL: The Stream
LOCAL CHANNEL: Email
LOCAL CHANNEL: Yammer
---Now scrolling
LOCAL CHANNEL: (null)
LOCAL CHANNEL: (null)
LOCAL CHANNEL: The Stream

1 个答案:

答案 0 :(得分:1)

尝试按以下方式更改您的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LocalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }

    cell.labelOutlet.text = [[localArray objectAtIndex:[indexPath row]] localChannel];
    cell.sliderOutlet.value = [[[localArray objectAtIndex:[indexPath row]] localPercentage] intValue];

    return cell;
}
相关问题