IOS-根據TableviewCell 總體高度 做自適應

//自適應高度

- (void)chanageHeight

{

    //誰在最下面用誰  也就是你最後一個控件

    CGRect aRect1 = self.contentView.frame;

    aRect1.size.height = self.backGroundImageV.frame.size.height+self.backGroundImageV.frame.origin.y;

    self.contentView.frame = aRect1;

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    LCAboutBallTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {

        cell = [[LCAboutBallTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        

        cell.dataArray = [_dataArray objectAtIndex:[indexPath row]];//數據傳到cell

        

        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

        cell.backgroundColor = [UIColor clearColor];

    }

    [cell createView];

    cell.collectionButton.tag = indexPath.row;

    [cell.collectionButton addTarget:self action:@selector(collectionButton:) forControlEvents:UIControlEventTouchUpInside];

    

    [cell chanageHeight];  //調用自適應方法

    return cell;

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{


    CGFloat cellHeight=0;

    @autoreleasepool {  //此處根據cell  返回總體高度

        LCAboutBallTableViewCell *cell=(LCAboutBallTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];

        cellHeight=cell.contentView.frame.size.height;

        return cellHeight;

    }

}



發佈了43 篇原創文章 · 獲贊 11 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章