2015-12-02 47 views
0

我用下面的代碼來縮放圖像到我的UIImageView。桌子第一次加載時一切都很好。但是當我滾動tableview時,所有的圖像方面都被打破了。的UIImageView看點不適合工作時的tableview滾動

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProductCell" forIndexPath:indexPath]; 

    [self configureCustomCell:(ProductsTableViewCell*)cell atIndexPath:indexPath]; 

    return cell; 
} 

- (void)configureCustomCell:(ProductsTableViewCell*)cell atIndexPath:(NSIndexPath *)indexPath { 

    NSURL *url = [NSURL URLWithString:[[arr_products objectAtIndex:indexPath.section] productImage]]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 

    __weak UITableViewCell *weakCell = cell; 

    [cell.productPhotoImage setImageWithURLRequest:request placeholderImage:nil 
      success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 
       weakCell.imageView.image = image; 
       weakCell.imageView.contentMode = UIViewContentModeScaleAspectFit; 
       weakCell.imageView.clipsToBounds = YES; 
       weakCell.imageView.frame = CGRectMake(5, 5, 60, 60); 
      } 
    failure:nil]; 
} 
+0

請在' - tableView:cellForRowAtIndexPath:'中顯示你的代碼。 – KudoCC

+0

@serdar aylanc是你使用自定義單元? – satheesh

+0

@satheesh我更新了問題中的代碼 –

回答

0

如果你想從服務器獲取的圖像,然後將其加載tableviewcell將無法正常升級電池,

可以使用SDWebImage庫從服務器加載圖像,檢查此鏈接SDWEbImage

如果你想添加活動的指標檢查這個https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage

#import <SDWebImage/UIImageView+WebCache.h> 

中的cellForRowAtIndexPath

[weakCell.myImage setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"mawgif-log.png"] options:SDWebImageRefreshCached usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];