Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically changing width or height not working for Mac app

I have a very strange issue. I need to programmatically increase my TableView height. But programmatic frame change in terms of width or height isn't been aplied. Is there some other way of changing frames in Cocoa?

I’m using the following code:

-(IBAction )topButtonClicked:(id)sender{
    if(testView.isHidden == NO){
        [testView setHidden:YES];
        [tableView setFrame:NSMakeRect(0,595, 666,595+120)];
}
    else {
        [tableView setFrame:NSMakeRect(0,595, 666,595)];
        [testView setHidden:NO];
    }
}

like image 730
Swastik Avatar asked Aug 14 '26 12:08

Swastik


1 Answers

By default, a table view is enclosed in a scroll view and the scroll view is configured to automatically resize its subviews. This means that changing the table view frame alone won’t work because the enclosing scroll view will autoresize it.

You should change the frame of the enclosing scroll view instead. For example:

[[tableView enclosingScrollView] setFrame:NSMakeRect(0,595, 666,595+120)];

or you could have an outlet for the scroll view:

[tableScrollView setFrame:NSMakeRect(0,595, 666,595+120)];

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!