benGshore
benGshore

Reputation: 65

Table View Cell Does Not Reload When Scrolling

I have a table view with prototype cells set up, when the view first loads the correct values for my label and slider are populated correctly for each cell. When i scroll down/up the the cells that go out of view on the screen do not seem to be reloading. They have a null value.

My data is source is an mutable array (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;
}

Logging

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

Upvotes: 1

Views: 188

Answers (1)

Sergei Nikitin
Sergei Nikitin

Reputation: 788

Try to change your code as provided below:

- (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;
}

Upvotes: 1

Related Questions