2013-03-22 45 views
-2

iOS如何在UITableViewCell中显示多个图像。 UITableViewCell中的第一张图像应该是固定的(,即不应该从视图滚动)。ios如何在uitableviewcell中显示多个图像

+1

尝试使用customcell – 2013-03-22 06:33:10

+0

http://www.appcoda.com/customize-table-view-cells-for-uitableview/ – BhushanVU 2013-03-22 06:34:57

+0

是要显示像网格格式 – 2013-03-22 06:36:47

回答

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; 
} 
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主代码。

+0

对于由步骤更多的细节和步骤教程请在这里参考http://sugartin.info/2011/09/02/custom-table-view-which-contains-more-then-one-images/。 – 2013-03-22 06:40:57

相关问题