how to show image in table cell through json parsing

前端 未结 4 1521
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 14:51
NSURL *url = [NSURL URLWithString:@\"yourimage\"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[[UIImage alloc] initWithData:data] autorelease];
<         


        
4条回答
  •  情话喂你
    2021-01-26 14:51

    try this,

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    NSURL *url = [NSURL URLWithString:[imageArray objectAtIndex: [indexPath row]]];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *img = [[[UIImage alloc] initWithData:data] autorelease];
    [[cell imageView] setImage:img];
    
    return cell;
    }
    

提交回复
热议问题