I have a UITableView that displays content programmatically.
The cells load fine when first opened, but after scrolling they all show the same caption, which is, I assume, the last cells caption.
The underlying TableView that opens if a cell is selected still works fine.
I looked up the solutions on SO but they either didn’t work for me or I’m too dumb to understand the Problem, which sees to be the reusing the cells for some kind of saving resources.
I will post the cellForRowAtIndexPath as I assume the Problem lies there, if any further code is needed please let me know.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *oneLine = [entrys objectAtIndex:position];
NSArray *lineComponents = [oneLine componentsSeparatedByString:@";"];
cell.textLabel.text = [lineComponents objectAtIndex:0];
cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:0.8 blue:0.2 alpha:1.0];
if (position < [entrys count] -2 ) {
position++;
}
return cell;
}
Thanks in advance
You’re not using the
indexPathparameter at all. It should proably be: