我有一個tableview中SDWebImage的UIImageView +中的WebCache定製的UIImageView
此代碼的工作完美,但圖像放置怪異和醜陋的我的tableview從我的web服務器加載圖像的問題到我的UIImageView:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the cell. Note that this name is the same as in the storyboard
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//Set the correct name in the cell.
//Do so by looking up the row in indexpath and choosing the same element in the array
NSInteger currentRow = indexPath.row;
Image* currentImage = [self.images objectAtIndex:currentRow];
// Here we use the new provided setImageWithURL: method to load the web image
[cell.imageView setImageWithURL:[NSURL URLWithString:currentImage.src] placeholderImage:[UIImage imageNamed:@"testimage.jpg"]];
return cell;
}
所以我創建了一個的UIImageView我的故事板,並改變了代碼如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the cell. Note that this name is the same as in the storyboard
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//Set the correct name in the cell.
//Do so by looking up the row in indexpath and choosing the same element in the array
NSInteger currentRow = indexPath.row;
Image* currentImage = [self.images objectAtIndex:currentRow];
UIImageView *imgView = (UIImageView *)[cell viewWithTag:100];
// Here we use the new provided setImageWithURL: method to load the web image
[imgView setImageWithURL:[NSURL URLWithString:currentImage.src] placeholderImage:[UIImage imageNamed:@"testimage.jpg"]];
return cell;
}
但是,如果我跑我的設備上運行此代碼,我得到一個西尼亞l SIGABRT錯誤。
我如何才能在我的自定義Imageview上工作?
你確定這個單元有一個viewWithTag 100嗎? – manujmv
是的。現在我已經將它從100改爲1000,並且它正在工作。 –