ios Cutom tableview cell subview彼此重叠

时间:2015-05-15 14:10:40

标签: ios uitableview uiimageview

我创建了两个自定义单元格,其中包含 UILabel UIImageView 。 即使我在它们之间添加了空格,UIImageView单元格也与UILabel单元格重叠。另外,我正在更新UIlabel单元格的框架,但它没有更新。我没有使用autolayout。任何人都能为我解决这个问题吗?

enter image description here

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetermineCoatingCell *cell=[[NSBundle mainBundle] loadNibNamed:@"DetermineCoatingCell" owner:self options:nil][0];
    float cellHeight = [self tableView:tableView heightForRowAtIndexPath:indexPath];
    NSDictionary *option =[arrOptions objectAtIndex:indexPath.row];

    if (is_iPad) {
        // float yValue=(cellHeight/2)-10;
        lblTable= [[UILabel alloc]initWithFrame:CGRectMake(30, 5, 590, cellHeight)];
        lblTable.font=[UIFont systemFontOfSize:30];
        lblTable.numberOfLines=0;
        lblTable.textColor=[UIColor colorWithRed:63.0/255.0f green:126.0/255.0f blue:199.0/255.0f alpha:1.0];
        lblTable.textAlignment=NSTextAlignmentLeft;    
    } else {
        // float yValue=(cellHeight/2)-5;
        if (![option[@"CoatingImage"] isEqualToString:@""]) {    
            cell.imgView.tag = indexPath.row;
            cell.imgView.userInteractionEnabled = YES;

            UITapGestureRecognizer *tapgesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgViewTapped:)];
            tapgesture.numberOfTapsRequired = 1;              
            tapgesture.view.tag = indexPath.row;
            tapgesture.cancelsTouchesInView = NO;
            //  [tapgesture setValue:[NSString stringWithFormat:@"%ld",indexPath.row] forKey:@"Tag"];

           [cell.imgView addGestureRecognizer:tapgesture];

            NSString *key = [[option valueForKey:@"CoatingImage"] MD5Hash];
            NSData *data = [FTWCache objectForKey:key];
            if (data) {
                UIImage *image = [UIImage imageWithData:data];
                cell.imageView.image=image; 
            } else {              
                [WebImageOperations processImageDataWithURLString:[option valueForKey:@"CoatingImage"] andBlock:^(NSData *imageData) {

                    [FTWCache setObject:imageData forKey:key];
                    UIImage *image = [UIImage imageWithData:imageData];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        cell.imageView.image=image;
                    });          
                }];
            }
        } else { 
            CGRect framelbl  = CGRectMake(0,0, cell.lblTitle.frame.size.width,cell.lblTitle.frame.size.height);

            NSLog(@"%@",NSStringFromCGRect(framelbl));
            [cell.lblTitle setFrame:framelbl];
        }
    }
    cell.lblTitle.text=[NSString stringWithFormat:@"%@",[option valueForKey:@"AnswerOptionText" ]];

    cell.lblTitle.textColor=[UIColor  colorWithRed:63.0/255.0f green:126.0/255.0f blue:199.0/255.0f alpha:1.0];

    NSLog(@"lblTableText %@",lblTable.text);

    if(selectedPath.row == indexPath.row  && selectedPath.section == indexPath.section)
    {
        cell.backgroundColor = [UIColor colorWithRed:227.0/255.0f green:227.0/255.0f blue:227.0/255.0f alpha:1.0];;
    } else {
        cell.backgroundColor = [UIColor clearColor];
    }

    return cell;
}

1 个答案:

答案 0 :(得分:0)

如果您确定在表视图中不使用autolayout,则调查表视图委托方法 - [id tableView:heightForRowAtIndexPath:]:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath

您需要确定哪一行对应于图像视图单元格,哪一行对应于标签单元格,然后返回适当的高度。