1

Drag and drop UITableViewHeader

enter image description here

You can look at an orange color UITextView.

enter image description here

I set the height constant of the tableview is zero.

After reloading the tableview total height of UITableView showing same as previous(as no UITextView showing)

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.heightConstCommentBox.constant = 0;

    [self configureTableviewFooter];

}

-(void)configureTableviewFooter{
    //More button Configure

    height =  50 +[self recusiveDescription:self.viewFooter] ;

    // Assign new frame
    self.viewFooter.frame =  CGRectMake(self.viewFooter.frame.origin.x, 
    self.viewFooter.frame.origin.y,self.viewFooter.frame.size.width ,  height); // viewFooter is container view of tableFooterView

    self.tableView.tableFooterView = self.viewFooter;
    [self.tableView reloadData];

}

- (float )recusiveDescription:(UIView *)view
{
    NSString *s = @"";
    float height = 0;

    NSArray *subviews = [view subviews];
    if ([subviews count] == 0) return 0;

    for (UIView *subView in subviews) {

    height = height + subView.frame.size.height ;

        [self recusiveDescription:subView];
    }
    return height;
}

After reloading the tableview , table view footer size not changing.

Itachi
  • 5,777
  • 2
  • 37
  • 69
Shourob Datta
  • 1,886
  • 22
  • 30
  • 1. Check [this variable row height](https://stackoverflow.com/a/18746930/1677041) issue first. 2. Paste out more code about your `UITableView` instead of your controllers, please. – Itachi Jul 09 '19 at 02:45

2 Answers2

0

In method recusiveDescription:(UIView *)view you use the frame property of the subview. But for the autolayout it is not correct. To get future size of the view, call:

- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize 
        withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority 
              verticalFittingPriority:(UILayoutPriority)verticalFittingPriority;

This method returns the optimal size for the view based on the provided constraint priorities.

Also I did not understand why do you call recusiveDescription in recusiveDescription: and do not use result value.

Andrew Romanov
  • 4,774
  • 3
  • 25
  • 40
0

u can use following in case u used custom cell for table.

in following code replace postss[index.row].post with your label content and +230 is minimum height of your cell. or u can say its height of other view other than label.

automatic dimension method will work only if u have 1 label or 1 textfield,1 textview.

and don't fix your label's height.

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let heightOfRow = self.calculateHeight(inString: postss[indexPath.row].post)
    return (heightOfRow + 230)
}

//custom function for calculate dynamic height
func calculateHeight(inString:String) -> CGFloat
{
    let messageString = inString
    let attributes : [NSAttributedString.Key : Any] = [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 15.0)]

    let attributedString : NSAttributedString = NSAttributedString(string: messageString, attributes: attributes)

    let rect : CGRect = attributedString.boundingRect(with: CGSize(width: 370, height: CGFloat.greatestFiniteMagnitude), options: .usesLineFragmentOrigin, context: nil)

    let requredSize:CGRect = rect
    return requredSize.height
}
kishan vekariya
  • 431
  • 3
  • 11