【发布时间】:2012-10-17 05:23:52
【问题描述】:
大家好,我有自定义单元格,其中有UIImageView 和UILabel 我想将图像分配给UIImageView,将文本分配给UILabel,它们在数组中,有人可以帮我吗?提前致谢
我试过下面的代码
- (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];
}
cell.textLabel.text =[CurArray objectAtIndex:indexPath.row];
NSString *cellIcon = [[self IconArray] objectAtIndex:indexPath.row];
UIImage *cellIconimage = [UIImage imageNamed:cellIcon];
UIImageView *imageView = [[UIImageView alloc] initWithImage:cellIconimage];
[imageView setFrame:CGRectMake(100.0, 30.0, 30.0, 30.0)];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[cell addSubview:imageView];
return cell;
}
使用此代码,我可以将图像分配给创建的图像视图,但我无法为 UILable 分配文本
【问题讨论】: