After BLOCK Completed only Return

后端 未结 3 1308
别跟我提以往
别跟我提以往 2020-12-22 15:28

May I know is what are the solution to use in order to make the following code working in order.

- (CGFloat)getRowImageHeight
{
    CGFloat defaultHeight   =         


        
3条回答
  •  醉话见心
    2020-12-22 15:50

    Things that I am trying to do is at view load, I preload the image before it appears on the view. Then get image block to return the image height and I wanted to return back the height to

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

    But it seems that answers above told me that the approach is impossible. So I tried to use delegate and return the height to main view and update the cell height by using the code below after the image has been successfully fetch at cell level.

    - (void)reloadItemImageTVCellHeight:(CGFloat)height
    {
        if( !self.hasUpdatedImageCellHeight ){
            self.hasUpdatedImageCellHeight   = YES;
            self.itemImageCellHeight        = height;
            [self.mTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:ROW_IMAGE inSection:0]]
                             withRowAnimation:UITableViewRowAnimationNone];
        }
    }
    

    In viewDidLoad, I've set self.hasUpdatedImageCellHeight to NO and self.itemImageCellHeight to 300.f. self.hasUpdatedImageCellHeight is to control whether the delegate has already return me any value, if YES then I will update it to YES in order to prevent the delegate codes keep calling again & again.

    This is my approach for it, but still it is best if there is an approach that can know the image height natively before the table view being completely loaded.

提交回复
热议问题