开发者

Why my UITableView not smooth when scroll first time?

My table view cell has four labels. The table view is not smooth when scroll in first time. After all cells displayed one time, the scrolling is so smooth with no problem. So I thought the problem is the speed of loading one cell in the first time.

I have reuse cell but the problem is not solved. Please help me! Thanks so much!

Here is my code:

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"MyIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"ForumListTableViewCell" owner:self options:nil];
        cell = [views objectAtIndex:0];
    }

    NSDictionary *cate = [_forums objectAtIndex:indexPath.s开发者_如何学编程ection];
    NSArray *forumsInCate = [cate objectForKey:@"forums"];
    NSDictionary *forumInfo = [forumsInCate objectAtIndex:indexPath.row];

    // title1
    UILabel *forumTitleLabel = (UILabel *)[cell viewWithTag:1];
    forumTitleLabel.text = [forumInfo objectForKey:@"name"];

    // master
    UILabel *masterLabel = (UILabel *)[cell viewWithTag:2];
    NSString *master = [forumInfo objectForKey:@"moderators"];
    masterLabel.text = master;

    // title2
    UILabel  *threadTitleLabel = (UILabel *)[cell viewWithTag:3];
    NSString *lastPostTitle;
    NSDictionary *lastPostInfo = [forumInfo objectForKey:@"lastpost"];
    lastPostTitle = [lastPostInfo objectForKey:@"subject"];
    threadTitleLabel.text = lastPostTitle;

    // author
    UILabel *authorLabel = (UILabel *)[cell viewWithTag:4];
    authorLabel.text = [NSString stringWithFormat:@"%@ / %@",
                        [forumInfo objectForKey:@"threads"],
                        [forumInfo objectForKey:@"posts"]
                        ];

    return cell;    
}


NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"ForumListTableViewCell" owner:self options:nil];

on .h

NSArray *views;

on .m

-(void)viewDidLoad
{
    [super viewDidLoad];
    views = [[NSBundle mainBundle] loadNibNamed:@"ForumListTableViewCell" owner:self options:nil];
}

- (void)dealloc
{
    //--- other object ----
    [views release];
    [super dealloc];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜