How to add images to UITableView cell?

后端 未结 5 1371
暖寄归人
暖寄归人 2021-02-09 16:57

I temporarly added some values to the UITableViewCell programmatically. But I need to add images to each cell. How can I do that?

Here is my code. .h file

5条回答
  •  名媛妹妹
    2021-02-09 17:21

    Move return cell; at the end of the method:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
        if (cell == nil) { cell = [[[UITableViewCell alloc]
                                    initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
        }
        NSUInteger row = [indexPath row]; 
        cell.textLabel.text = [listData objectAtIndex:row]; 
    
    
        UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
        imv.image=[UIImage imageNamed:@"user.jpg"];
        [cell.contentView addSubview:imv];
        [imv release];
    
        return cell;
    }
    

提交回复
热议问题