1

i have AQGridView view with 45 items in GridView (12 rows), problem occurs when I scroll the view and grid gets laggy when new row is created. I am thinking about creating the whole rows once and using it from cache or something, without asking to create it every time when I scroll, because it's not usable and doesn't look fine when it lags. Thanks

- (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 );
}
Ignas S
  • 85
  • 1
  • 8

1 Answers1

0

This is because you are creating plain plainCell2 again and again

Using dequeueReusableCellWithIdentifier for the tableView/gridview, you can greatly speed things up. Instead of instantiating a lot of cells, you just instantiate as many as needed, i.e. as many that are visible (this is handled automatically).But you are creating a new one each time

Replace this

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

with this

     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];
}
Quamber Ali
  • 2,170
  • 25
  • 46