2013-08-27 56 views
1

我在GridView(12行)中有45個項目的AQGridView視圖,當我滾動視圖時,會發生問題,當創建新行時,網格會變得遲緩。我正在考慮一次創建整行並從緩存或其他東西中使用它,而不是每次滾動時都要求創建它,因爲它不可用,並且在它滯後時看起來不太好。由於滾動AQGridView項目時出現滯後現象

- (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); 
} 
+0

能你可以分享一些你已經實現的代碼嗎? –

+0

我想看看你的單元格索引方法 –

+0

好的,這裏是我的[方法](http://pastebin.com/3wKNM2JZ) –

回答

0

這是因爲你再次創造純plainCell2,再次

使用dequeueReusableCellWithIdentifier了的tableView/GridView控件,您可以 大大加快速度。取而代之的實例很多細胞的,你 只是實例儘可能多的需要,即作爲許多是可見的 (這是自動處理的),但要創建一個新的每個 時間

替換此

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]; 
} 
+0

我以前試過,它不會加快速度。無論如何,謝謝你的幫助! –

+0

這是我在上面的代碼中可以看到的唯一問題。如果除了那個之外還有其他的東西,請添加它 –