UITableView with Custom Cell only loads one row of data at a time
- by Anton
For my table, I've created a custom cell that has two labels. I also have two arrays with data, that I use to respectively assign each label in the cell.
My problem, is that when the table is viewed, only the first row has data, and the rest of the data "sorta" loads when I start scrolling down. By "sorta", only the first row will load at a time. The only time I get to see all the data, is when I scroll to the bottom, then scroll up again.
I've used the cellForRowAtIndexPath method to load the data into my cell.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
CustomCell *cell = (CustomCell *)[tableView
dequeueReusableCellWithIdentifier:CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell"
owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[CustomCell class]])
cell = (CustomCell *)oneObject;
}
NSUInteger row = [indexPath row];
//I have two tables to fill up, hence the tag if statement
if ([tableView tag] == 0) {
cell.arriveTimeLabel.text = [homeBoundTimes objectAtIndex:row];
cell.departTimeLabel.text = [homeBoundTimes objectAtIndex:row];
} else if ([tableView tag] == 1) {
cell.arriveTimeLabel.text = [workBoundTimes objectAtIndex:row];
cell.departTimeLabel.text = [workBoundTimes objectAtIndex:row];
}
return cell;
}
Is it possible that its only getting called when the top cell is being called?