滚动AQGridView项目时出现延迟

时间:2013-08-27 08:25:45

标签: ios xcode uiscrollview aqgridview

我在GridView中有45个项目的AQGridView视图(12行),当我滚动视图时出现问题,并且在创建新行时网格变得迟钝。我正在考虑创建整行一次并从缓存或其他东西使用它,而不是每次滚动时都要求创建它,因为它不可用并且当它滞后时看起来不太好。感谢

- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) `enter code here`index
{
    NSString *fullThumbPath = [itemsList objectAtIndex:index];
    int startOfThumbWord = [fullThumbPath rangeOfString:@"bundle"].location;
    NSString *shortThumbPath = [fullThumbPath substringFromIndex:startOfThumbWord+7];
    if (
        ([vieta isEqualToString:@"cover"] || [vieta isEqualToString:@""]) && [labelis isEqualToString:@""]) {
        static NSString * PlainCellIdentifier = @"ImageCell";
        AFInstallerImageCell2 * plainCell2 = (AFInstallerImageCell2 *)[aGridView dequeueReusableCellWithIdentifier: PlainCellIdentifier];
            plainCell2 = [[AFInstallerImageCell2 alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0) // 330
                                                    reuseIdentifier: PlainCellIdentifier];

    plainCell2.selectionStyle = AQGridViewCellSelectionStyleNone;
    plainCell2.path = [target stringByAppendingPathComponent:shortThumbPath];//[itemsList objectAtIndex:index];
    plainCell2.image = [UIImage imageWithContentsOfFile:[itemsList objectAtIndex:index]];
    plainCell2.layer.shouldRasterize = YES;
    NSString *shortThumbPath = [fullThumbPath substringFromIndex:startOfThumbWord+30];

    shortThumbPath = [shortThumbPath stringByReplacingOccurrencesOfString:@"/Thumb.png"
                                         withString:@""];

    NSString *title = [[shortThumbPath lastPathComponent] stringByDeletingPathExtension];
    plainCell2.title = [title stringByReplacingOccurrencesOfString:@"_" withString:@" "];
    return ( plainCell2 );
}

1 个答案:

答案 0 :(得分:0)

这是因为您一次又一次地创建普通的 plainCell2

  

对tableView / gridview使用dequeueReusableCellWithIdentifier,你可以   大大加快了速度。你没有实例化很多细胞   只需要根据需要实例化,即尽可能多的实例化   (这是自动处理的。)但是你要分别创建一个新的   时间

替换

 AFInstallerImageCell2 * plainCell2 = (AFInstallerImageCell2 *)[aGridView dequeueReusableCellWithIdentifier: PlainCellIdentifier];
            plainCell2 = [[AFInstallerImageCell2 alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0) // 330
                                                    reuseIdentifier: PlainCellIdentifier];

使用此

     AFInstallerImageCell2 * plainCell2 = (AFInstallerImageCell2 *)[aGridView dequeueReusableCellWithIdentifier: PlainCellIdentifier];
              if(plainCell2 ==nil) { 
plainCell2 = [[AFInstallerImageCell2 alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0) // 330
                                                        reuseIdentifier: PlainCellIdentifier];
}