2014-10-20 34 views
0

我有一個從我的Url加載圖像的TableView,一切都很好。問題是當我向下或向上滾動時,圖像在單元格中變大。有時它變得比它自己的細胞更大。表格查看特定大小的細胞圖像

我已經嘗試了所有的東西,但它不工作,我坐在視圖模式,以適應方面,但仍然有同樣的問題。

她是我的代碼:

static NSString *cellIdentifier = @"Cell"; 
CellView *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; 

if (!cell) { 
cell = [[CellView alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
} 

ListOfObjects *listObjects; 

cell.accessoryType = UITableViewCellAccessoryNone; 
listObjects = [listArray objectAtIndex:indexPath.row]; 
cell.userName.text = userName; 


ListOfObjects *venue = ((ListOfObjects *)self.listArray[indexPath.row]); 
NSString *one = listObjects.theUserId; 
NSURL *myUrl = [NSURL URLWithString:one]; 

if (listObjects.image) { 
cell.imageView.image = listObjects.image; 
} else { 
// set default user image while image is being downloaded 
cell.imageView.image = [UIImage imageNamed:@"second58.png"]; 

// download the image asynchronously 
[self downloadImageWithURL:myUrl completionBlock:^(BOOL succeeded, UIImage *image) { 
if (succeeded) { 
// change the image in the cell 

cell.imageView.image = image; 

// cache the image for use later (when scrolling up) 
venue.image = image; 
} 
}]; 
} 

任何一個可以給我一個關於它的想法?

+0

添加代碼,其中的邏輯是有 – 2014-10-20 04:15:19

+0

你可以發佈圖片的問題?你是什​​麼意思,他們比單元格更大?它們是否放大或溢出視圖?檢查cellView上的contentView,然後檢查heightForRow以及tableView自身的寬度,看看它是否適用於您的圖像 – noobsmcgoobs 2014-10-20 05:07:11

+0

圖像溢出了單元格,不幸的是我無法發佈圖像,因爲我是新用戶。讓我們說原始圖像幀大小(40 * 40),從我的網址加載表後,向下滾動圖像變大,讓我們說(100 * 100) – 2014-10-20 05:19:43

回答

0

也許你可以調整圖像幀:

[self downloadImageWithURL:myUrl completionBlock:^(BOOL succeeded, UIImage *image) { 
if (succeeded) { 
cell.imageView.image = image; 
cell.imageView.frame = your.frame; 
} 
}]; 

如果緩存的形象,你應該設置它的框架,當你使用它,而不是隻有當它完成下載

+0

仍然有同樣的問題!只要我向下滾動圖像變大。 – 2014-10-20 04:29:16

+0

將代碼添加到您正在面臨的問題中 – 2014-10-20 04:42:59

+0

是您的單元釋放,並在其中放置了一個通用單元格? – noobsmcgoobs 2014-10-20 05:24:11