如何在tableview单元格中显示图像?字符串未传递给tableview

时间:2014-10-10 05:41:07

标签: iphone uitableview tableviewcell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"HistoryCell";   
    //UITableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    UITableViewCell * Cell=[tblView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (Cell == nil)
    {
        Cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        Cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

    myString=[arr objectAtIndex:indexPath.row];
    NSLog(@"String %@",myString);

    //NSString *newString = [myString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

    NSURL *imageURL =[NSURL URLWithString:myString];    
    NSData *image = [[NSData alloc] initWithContentsOfURL:imageURL];    
    UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(00, 00, 80, 80)];

    imageview.image=[UIImage imageWithData:image];
    [Cell addSubview:imageview];
    //cell.imageView.image=[UIImage imageWithData:image];

    return Cell;
}

1 个答案:

答案 0 :(得分:0)

请进行以下更正:

static NSString *cellIdentifier = @"HistoryCell";   
UITableViewCell * Cell=[tblView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

这可能是缺少的话......