简体   繁体   English

为什么第一次滚动时我的UITableView不流畅?

[英]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.section];
    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 在.h上

NSArray *views;

on .m 在.m上

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM