开发者

UITableViewCell showing indexpath rows out of order

Odd question, I am creating a UITableView, setting 8 rows of data. Simply, I'm just returning the ind开发者_StackOverflow社区expath row to try and figure out what is wrong, but ultimately, any rows that are off screen seem to load in a strange order.

For example, rows 0,1,2,3,4,5 all appear ok on first load, but then 6 & 7 are off screen. When I scroll to them I usually see rows 6 and 0, or 6 and 1. I then see row 7 appear back at the top of the table when I scroll back up.

Here's my code:

- (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] autorelease];

        [cell.textLabel setText:[NSString stringWithFormat:@"Row: %d", [indexPath row]]];
    }

    return cell;
} 

Am I doing something really stupid? Cheers


You can use

NSString *cellIdentifier =[NSString stringWithFormat:@"%d",indexPath.row];

instead of

static NSString *CellIdentifier = @"Cell";


Create your cell in the if statement and then set the properties (ie the label) outside the if statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜