简体   繁体   English

自动调整TableViewCell的高度以适合iOS 6中的UIImageVIew

[英]Auto resizing the height of TableViewCell to fit the UIImageVIew in iOS 6

I have uiimageview property to display image in my table view and would like to let one specific table view cell to change its height according to the height of the image in the uiimageview. 我有uiimageview属性,可以在表格视图中显示图像,并希望让一个特定的表格视图单元格根据uiimageview中图像的高度来更改其高度。 Below is what I did. 以下是我的工作。 Not really sure why the height of the tableview cell didn't change... :( 不太确定为什么tableview单元格的高度没有变化... :(

@interface BoatViewController () <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate>

 @property (nonatomic, weak) IBOutlet UIImageView *boatImageView; - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0 && indexPath.row == 0) { return self.boatImageView.image.size.height; }else{ return 44; } } 

try reloading the table view data when everything has finished loading. 一切完成加载后,尝试重新加载表视图数据。 It may be that when that method was called, iOS hadn't finished calculating the final size of the frame. 可能是当调用该方法时,iOS尚未完成框架最终尺寸的计算。

In your viedDidAppear method add the call to reload the tableview. 在viedDidAppear方法中,添加调用以重新加载tableview。 See if it helps at all. 看看是否有帮助。

Try this Code hope it help. 尝试此守则,希望对您有所帮助。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {

    CGSize size = image.size; // Assign the image what you want to display.

  //  self.boatImageView.frame=CGRectMake(0, 0, size.width, size.height);

    return size.height;

    }else{
        return 44;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM