开发者

tableview disappears after changing view size

following code:

self.dataTableViewController = [[DataTableViewController alloc] initWithStyle:UITableViewStylePlain];
CGRect tableViewRect = self.dataTableViewController.view.frame;
tableViewRect.origin.x = 0.0f;
tableViewRect.origin.y = 91.0f;
//tableViewRect.size.width = 320.0f;
//tableViewRect.size.height = 613.0f;
self.dataTableViewController.view.frame = tableViewRect;
[self.view addSubview:self.dataTableViewController.view];

my tableviewcontroller shows up and everything is working, its also positioned on the right position. but the size of my table is not correct. if i uncomment my two lines of code for the size property, the tableview disappears from my uiview and i have no idea why.

some ideas?

// edit:

okay there's a strange behavior. my viewcontroller where my tableview gets displayed is in a splittableviewcontroller (left side)

self.contentSizeForViewInPopover = CGSizeMake(320.0, 704.0); does not have any effect on my popovercontroller. i left it default, from the splittableviewcontroller template. its always the full height if i'm in portrait mode.

uncommenting tableViewRect.size.height = 613.0f; works, uncommenting the width not. setting my height to 613px i get a tableview which is 313px high. What!? Setting my height to 913.0f works, its perfect in 开发者_如何转开发landscape AND portrait. what i don't understand is, in landscape it should only be 613px high. and i would like to set the height of my popover to the same height as my viewcontroller in landscape, so that my tableview is always 613 high. no idea whats happening there.

my tableview with 913px:

tableview disappears after changing view size

tableview disappears after changing view size


You are trying to insert the table view as subview of another view. Then you try to specify a frame. What may happen is that even if you specify the frame, your table is still a subview of another view and then it will be subject to any autoresizing rule you may have initially set. So have you checked that setting the frame explicitly is not conflicting with the table autoresizing mask? in particular, you can try by setting for the table autoresizing mask the value

UIViewAutoresizingNone
(do this in the viewDidLoad method is recommended).


It works for me... Is your code inside a table view controller, or in some other classes? I tried this (and it works):

CGRect tableViewRect = self.tableView.frame;

tableViewRect.origin.x = 0.0f;
tableViewRect.origin.y = 91.0f;
tableViewRect.size.width = 320.0f;
tableViewRect.size.height = 613.0f;

self.tableView.frame = tableViewRect;

[self.tableView setNeedsLayout];
[self.tableView setNeedsDisplay];

BTW I think iPhone's dimension is 320 x 480, so I'm not sure why you're using 613 there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜