怎么将一个数组的内容放到tableview的cell中

2025-02-23 20:42:56
推荐回答(1个)
回答1:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

NSString *string = nil;

UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:string];

if (cell==nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:string];

}

//Array就是我的数组

cell.textLabel.text = [[Array objectAtIndex:indexPath.row] objectAtIndex:2];

cell.detailTextLabel.text = [[Array objectAtIndex:indexPath.row] objectAtIndex:6];

//下面的代码是设置图片的

NSString *str = @"http://cmhtech.ecartoon.net/";

NSString *str1 = [str stringByAppendingString:[[Array objectAtIndex:indexPath.row] objectAtIndex:4]];

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:str1]]];

cell.imageView.image = image;

//这个label是我自定义的

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(250, 2, 70, 20)];

label.text = [[Array objectAtIndex:indexPath.row] objectAtIndex:0];

[cell.contentView addSubview:label];

return cell;

}