怎么将一个数组的内容放到tableview的cell中
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;
}
{
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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询