簡體   English   中英

為什么第一次滾動時我的UITableView不流暢?

[英]Why my UITableView not smooth when scroll first time?

我的表格視圖單元格具有四個標簽。 第一次滾動時,表視圖不平滑。 在所有單元格顯示一次之后,滾動是如此順利,沒有問題。 所以我認為問題在於第一次加載一個單元的速度。

我有重用單元,但問題沒有解決。 請幫我! 非常感謝!

這是我的代碼:

// 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];

在.h上

NSArray *views;

在.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