Newbee
Newbee

Reputation: 3301

Not able to resize UITableView programmatically on iOS

I have added UITableView to a view, I want my application to work fine for both iPod 5th generation and lower versions(which is smaller in size), So I resized the table view height to its view height when loading, its not working, however if I resize the table in xib its working fine. What could be the problem. I suspect some property is restricting from doing this.

Please check the image below.

enter image description here

Black gap appears because of its size... Its not resizing..

I have set programatically also...

if (gui_status.device_type != OFI_VC_DVICE_TYPE_IPAD) {
        CGRect screenRect = self.table.frame;
        screenRect.size.height = 500; // with different height no change..
        [self.table setFrame:screenRect];
    }

Upvotes: 1

Views: 4244

Answers (4)

Gaurav Rastogi
Gaurav Rastogi

Reputation: 2145

Use AutoLayout to manage the height for UITableView and other subviews automatically whenever the screen size get changed

ScreenShot representing contraint for autolayout

Upvotes: 0

hitesh
hitesh

Reputation: 374

[table setFrame:CGRectMake(0, 0, 320, 500)];

Upvotes: 0

LittleIDev
LittleIDev

Reputation: 921

self.view.autoresizesSubviews = UIViewAutoresizingFlexibleHeight;  //self.view will be the superview of tableView

Try this.

Upvotes: 0

Wain
Wain

Reputation: 119041

Rather than setting the size explicitly, when you lay out the view in the XIB, set the auto-resizing rules so that the table view has flexible width and height and static top, bottom, left and right. Now, when iOS resizes the super view (done automatically) your table view will automatically be adjusted to fit.

Upvotes: 4

Related Questions