我有一个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,并且它正在工作。 –