在TableViewController中设置UIImage

时间:2013-11-17 23:21:15

标签: ios objective-c

我有以下代码,但在为UIImageView设置图像时出错:

[UITableViewCellContentView setImage:]: unrecognized selector sent to instance 0x17e87eb0'

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

    //Get image for the row
    UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
    NSURL *photoURL = [NSURL URLWithString:@"http://server.com/someimage.jpg"];
    UIImage *photo = [UIImage imageWithData:[NSData dataWithContentsOfURL:photoURL]];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.image = photo;
    cell.textLabel.text = @"test";

    return cell;
}

1 个答案:

答案 0 :(得分:2)

问题在于您尝试将邮件setImage发送到UITableViewCellContentView,这只是UIView并且没有图片属性。看起来你标记了细胞的错误部分。返回您的XIB或故事板,确保您已标记UIImageView 100。