Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UITableView resize height / cant scroll down issue

Beginner iOS Developer here.

What I have is a UITableVIewController that has 1 section with 3 static grouped cells. Under that I have a UIView that has some buttons and text fields, when pressing one of the buttons, the UIView height increases. My problem is I cant scroll down to see the content that is at the bottom of the UIView

Screenshots:

enter image description here

enter image description here

enter image description here

When the green plus button is pressed, these elements are moved down making room for some new elements to be inserted (which I haven't implemented yet as I am stuck on this issue)

EDIT

Here is an example project: https://www.dropbox.com/s/vamxr12n6rrsam7/resizeSample.zip

like image 522
RipzCurlz Avatar asked Jun 25 '26 14:06

RipzCurlz


2 Answers

You problem is that in your method to change the invoice. You only change the constraint of the invoiceBottomView, but you are not changing the size of invoiceBottomView's superview, that is the invoicePickerViewsContainer. So your tableView won't know you want to use more space of the tableFooterView (your invoicePickerViewsContainer).

You can change your code for this:

- (IBAction)invoiceLinesAddLine:(id)sender {

    [UIView animateWithDuration:.25 animations:^{

        CGRect invoiceBottomViewFrame = self.invoiceBottomView.frame;
        NSInteger invoiceBottomViewFrameHeight = invoiceBottomViewFrame.size.height;

        NSInteger invoiceLinesTopConstraintValue = invoiceLinesControlsViewTopConstraint.constant;
        NSInteger invoiceLinesBottomConstraintValue = invoiceLinesControlsViewBottomConstraint.constant;

        invoiceBottomViewFrameHeight = invoiceBottomViewFrameHeight + 40;
        invoiceLinesTopConstraintValue = invoiceLinesTopConstraintValue + 40;
        //invoiceLinesBottomConstraintValue = invoiceLinesBottomConstraintValue - 40;

        invoiceBottomViewFrame.size.height = invoiceBottomViewFrameHeight;
        invoiceLinesControlsViewTopConstraint.constant = invoiceLinesTopConstraintValue;
        invoiceLinesControlsViewBottomConstraint.constant = invoiceLinesBottomConstraintValue;

        CGRect invoicePickerViewsContainerFrame = self.invoicePickerViewsContainer.frame;
        invoicePickerViewsContainerFrame.size.height += 40;
        self.invoicePickerViewsContainer.frame = invoicePickerViewsContainerFrame;
        self.tableView.tableFooterView = self.invoicePickerViewsContainer;
        [self.view layoutIfNeeded];

    } completion:^ (BOOL finished){
        if (finished) {
            //actions when animation is finished
        }
    }];

}

You don't need to change the invoiceLinesBottomConstraintValue, because you will increment the invoicePickerViewsContainer's height.

Then you need to add again the tableFooterView, so the table view will know that the size change, and the table will change the contentSize

Now, you have problems with the pickers... But I don't understand why you have the pickers in this view. If you want to preserve those pickers inside that view, you will need to change the constraint of those or its frame.

like image 141
dcorbatta Avatar answered Jun 28 '26 05:06

dcorbatta


The way you setup the - (IBAction)invoiceLinesAddLine:(id)sender {} and the view within the tableview does not update the self.tableView.contentsize as you add more items. so add these lines to the completion function of the animation function within invoiceLinesAddLines and then twice the incremental height addition (i picked 80 arbitrarily)

 completion:^ (BOOL finished){
    if (finished) {
        //actions when animation is finished
        CGSize size=self.tableView.contentSize;
        size.height+=80;
        self.tableView.contentSize=size;
    }
}];
like image 37
Nate Avatar answered Jun 28 '26 05:06

Nate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!