UITableView在滚动后加载相同的标题

use*_*094 1 iphone xcode objective-c uitableview

我有一个UITableView以编程方式显示内容.

第一次打开时单元格加载正常,但滚动后它们都显示相同的标题,我认为是最后一个单元格标题.

如果选择单元格,则打开的基础TableView仍然可以正常工作.

我在SO上查找解决方案,但它们要么对我不起作用,要么我太愚蠢无法理解问题,这看起来是重复使用单元格来节省某些资源.

我将发布cellForRowAtIndexPath,因为我假设问题在那里,如果需要任何进一步的代码请告诉我.

- (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;
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

omz*_*omz 6

您根本没有使用该indexPath参数.它应该是:

NSString *oneLine = [entrys objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)