iOS如何在UITableViewCell
中显示多个图像。 UITableViewCell
中的第一张图像应该是固定的(即不应滚动视图)。
答案 0 :(得分:1)
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//static NSString *CellIdentifier = @"Cell";
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
/// You need to create UIImageView and add it to cell.contentView such like
UIImageView *imgView1 = [UIImageview alloc] init];
imgeView1.fram = CGRectMake(@"AS U WANT") // set specific fram as u want.
[cell.contentView addSubview:imgView1];// add as it is.
.
.
.
Create it as you want and add as it is.
}
return cell;
}
答案 1 :(得分:0)
这是UITableView的主要代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil){
cell=[[[NSBundle mainBundle] loadNibNamed:@"CCell" owner:self options:nil] objectAtIndex:0];
UIButton *imgV1=(UIButton*)[cell viewWithTag:1];
UIButton *imgV2=(UIButton*)[cell viewWithTag:2];
UIButton *imgV3=(UIButton*)[cell viewWithTag:3];
[imgV1 addTarget:self action:@selector(btnTapped:) forControlEvents:UIControlEventTouchDown];
[imgV2 addTarget:self action:@selector(btnTapped:) forControlEvents:UIControlEventTouchDown];
[imgV3 addTarget:self action:@selector(btnTapped:) forControlEvents:UIControlEventTouchDown];
HJManagedImageV *img1=[[HJManagedImageV alloc] initWithFrame:CGRectMake(0, 0, imgV1.frame.size.width, imgV1.frame.size.height)];
HJManagedImageV *img2=[[HJManagedImageV alloc] initWithFrame:CGRectMake(0, 0, imgV2.frame.size.width, imgV2.frame.size.height)];
HJManagedImageV *img3=[[HJManagedImageV alloc] initWithFrame:CGRectMake(0, 0, imgV3.frame.size.width, imgV3.frame.size.height)];
img1.tag=img2.tag=img3.tag=10000;
img1.backgroundColor=img2.backgroundColor=img3.backgroundColor=[UIColor clearColor];
[imgV1 addSubview:img1];
[imgV2 addSubview:img2];
[imgV3 addSubview:img3];
}
int x=indexPath.row;
x=x*3;
UIButton *imgV1=(UIButton*)[cell viewWithTag:1];
UIButton *imgV2=(UIButton*)[cell viewWithTag:2];
UIButton *imgV3=(UIButton*)[cell viewWithTag:3];
HJManagedImageV *img1=(HJManagedImageV*)[imgV1 viewWithTag:10000];
HJManagedImageV *img2=(HJManagedImageV*)[imgV2 viewWithTag:10000];
HJManagedImageV *img3=(HJManagedImageV*)[imgV3 viewWithTag:10000];
[img1 clear];
[img2 clear];
[img3 clear];
[imgV1 setTitle:[self.tableArray objectAtIndex:x] forState:UIControlStateDisabled];
img1.url=[NSURL URLWithString:[self.tableArray objectAtIndex:x]];
[img1 showLoadingWheel];
[GlobalCacheManager manage:img1];
if((x+1) >= self.tableArray.count){
imgV2.hidden=imgV3.hidden=YES;
[imgV2 setBackgroundImage:nil forState:UIControlStateNormal];
[imgV3 setBackgroundImage:nil forState:UIControlStateNormal];
} else if( (x+2)>=self.tableArray.count) {
img2.url=[NSURL URLWithString:[self.tableArray objectAtIndex:x+1]];
[img2 showLoadingWheel];
[GlobalCacheManager manage:img2];
imgV1.hidden=imgV2.hidden=YES;
imgV3.hidden=YES;
[imgV2 setTitle:[self.tableArray objectAtIndex:x+1] forState:UIControlStateDisabled];
[imgV3 setBackgroundImage:nil forState:UIControlStateNormal];
} else {
[img2 showLoadingWheel];
[img3 showLoadingWheel];
img2.url=[NSURL URLWithString:[self.tableArray objectAtIndex:x+1]];
[GlobalCacheManager manage:img2];
img3.url=[NSURL URLWithString:[self.tableArray objectAtIndex:x+2]];
[GlobalCacheManager manage:img3];
imgV2.hidden=imgV3.hidden=NO;
[imgV2 setTitle:[self.tableArray objectAtIndex:x+1] forState:UIControlStateDisabled];
[imgV3 setTitle:[self.tableArray objectAtIndex:x+2] forState:UIControlStateDisabled];
}
return cell;
}
您可以从here下载源代码。