UITableView Jerky,在ScrollView中每个单元最多可加载10个图像

时间:2014-07-07 05:50:31

标签: ios objective-c cocoa-touch uitableview

是的 - 这个问题已被问到很多。我发现的主要解决方案是使用drawRect用于tableViewCell,但是我没有看到如何在这种特定情况下实现它,因为我的缓慢加载特别是由于从NIB加载的单元格子视图的复杂性

我正在加载X表视图单元格。每个单元格都有一个标签,一个uiscroll视图。 uiscroll视图最多包含10个UIView项目,其中包含图像,标题和副标题的子视图。这显然是造成瓶颈不稳定的原因。

这是我的cellForRowAtIndexPath

HorizontalScroll *scroll = (HorizontalScroll *)[cell viewWithTag:TEN_ITEM_SLIDER_TAG_SLIDER];
        scroll.contentOffset = CGPointMake(-5, 0);
        scroll.contentInset = UIEdgeInsetsMake(0, 5, 0, 5);
        scroll.pagingEnabled = NO;

        [scroll resetItems];
        NSArray *items = [cellData objectForKey:@"items"];
        NSMutableArray *scrollItems = [[NSMutableArray alloc] init];
        for (int i = 0; i < [items count]; i++) {
            NSDictionary *item = [items objectAtIndex:i];

            NSArray *scrollItemXIB = [[NSBundle mainBundle] loadNibNamed:@"ScrollItemView" owner:self options:nil];
            UIView *scrollItemView = [scrollItemXIB lastObject];

            NSString *userId = ([[cellData objectForKey:@"sliderType"] isEqualToString:@"stores"]) ? [item objectForKey:@"id"] : [item objectForKey:@"userId"];
            NSString *resourceName = ([[cellData objectForKey:@"sliderType"] isEqualToString:@"stores"]) ? [item objectForKey:@"avatar"] : [item objectForKey:@"thumbnail"];

            ArgumentButton *scrollItemButton = (ArgumentButton *)[scrollItemView viewWithTag:SCROLL_ITEM_TAG_ICON];
            scrollItemButton.argument = item;
            scrollItemButton.argumentTwo = [cellData objectForKey:@"sliderType"];
            [scrollItemButton setImageWithURL:[APIController resourceUrlForUserId:userId resourceName:resourceName] forState:UIControlStateNormal];
            [scrollItemButton addTarget:self action:@selector(tenItemSliderItemSelected:) forControlEvents:UIControlEventTouchUpInside];

            UILabel *titleLabel = (UILabel *)[scrollItemView viewWithTag:SCROLL_ITEM_TAG_TITLE];
            NSString *title = ([[cellData objectForKey:@"sliderType"] isEqualToString:@"stores"]) ? [item objectForKey:@"storeName"] : [item objectForKey:@"title"];
            titleLabel.text = title;

            UILabel *subtitleLabel = (UILabel *)[scrollItemView viewWithTag:SCROLL_ITEM_TAG_SUBTITLE];
            NSString *subtitle = ([[cellData objectForKey:@"sliderType"] isEqualToString:@"stores"]) ? [item objectForKey:@"category"] : [NSString stringWithFormat:@"$%@", [item objectForKey:@"price"]];
            subtitleLabel.text = subtitle;

            if ([[cellData objectForKey:@"sliderStyle"] isEqualToString:@"numbered"]) {
                UIImageView *badgeIcon = (UIImageView *)[scrollItemView viewWithTag:SCROLL_ITEM_TAG_BADGE_ICON];
                badgeIcon.hidden = NO;

                UILabel *badgeLabel = (UILabel *)[scrollItemView viewWithTag:SCROLL_ITEM_TAG_BADGE_LABEL];
                badgeLabel.text = [NSString stringWithFormat:@"%i", i + 1];
                badgeLabel.hidden = NO;
            }

            [scrollItems addObject:scrollItemView];
        }

        [scroll loadItems:scrollItems];

0 个答案:

没有答案