2009-11-09 96 views
0

我剛寫的是從網站飼料和顯示的UITableViewCell讀一個小應用程序。我正在使用自定義視圖單元格,並且我的UITableView在滾動中旋轉,就像它在上下滾動時不太平滑一樣。任何想法?下面是我的UITableViewCell代碼,iPhone的UITableViewCell性能下降

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"CustomCell"; 

    CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     //  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil]; 
     for(id currentObject in topLevelObjects) { 
      if([currentObject isKindOfClass:[UITableViewCell class]]) { 
       cell = (CustomCell *) currentObject; 
       break; 
      } 
     } 
    } 
    //MiceAppDelegate *AppDelegate = (MiceAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    if(dataArray != nil) { 
     // 
     //NSArray *promoArray = (NSArray *) promotions; 
     NSDictionary *datadict = [self.dataArray objectAtIndex:indexPath.row]; 

     NSString *url = [datadict objectForKey:@"imageUrl"]; 
     NSString *title = [datadict objectForKey:@"title"]; 
     NSString *description = [datadict objectForKey:@"description"]; 

     NSString *newAddressPartOfURL = [url stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 

     //NSLog([url stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]); 

     NSURLResponse *urlResponse; 

     NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:newAddressPartOfURL]] returningResponse:&urlResponse error:nil]; 

     // Configure the cell. 
     UIImage *urlImage = [[UIImage alloc] initWithData:data]; 

     // NSLog(@"%i",[imageView.image topCapHeight]); 
     cell.title.text = title; 
     cell.description.text = description; 
     cell.image.image = urlImage; 
     [urlImage release]; 
    } 
    return cell; 
} 

回答

0

AFAIK的dequeueReusableCellWithIdentifier方法稱爲細胞得到沖洗等建立你的數據/做初始化請求,而不是在細胞的創造!

3

做同步下載作爲你的細胞都被吸收是肯定會引起一些不光滑滾動。您可以嘗試用asynchronous調用替換那些調用,並在下載過程中用普通對象填充數據。下載完成後,在你的tableview上調用reloadData。