PDA

View Full Version : need help getting my UITableView to scroll down far enough




manman
Sep 1, 2008, 09:38 PM
I'm pretty new to setting my views up outside of IB, and I need some help here. I'm setting up a table view with more cells than will fit on the screen, so you have to scroll to see them all. The problem is that that the table doesn't scroll down far enough to see the very last cell. It's only partially visible.

Here is some code to show how I set the table up (also, the status bar is showing and I there is a navigation bar at the top too.


{
UIView *contentView= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor blackColor];
contentView.autoresizesSubviews = YES;
self.view = contentView;
[contentView release];

myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
myTableView.delegate = self;
myTableView.dataSource = self;

[self.view addSubview:myTableView];

}


Thanks



Luke Redpath
Sep 2, 2008, 04:17 AM
It sounds like your tabie view isn't positioned in it's parent correctly.

Try changing:


initWithFrame:self.view.bounds


to:


initWithFrame:self.view.frame

manman
Sep 2, 2008, 10:57 PM
hi Luke, thanks a lot for the reply.

I did try that, but for some reason it ended up moving the table view down even further :confused:

What actually worked for me was setting up a CGRect like this

CGRect frame = self.view.bounds;
frame.size.height = frame.size.height - 40;


and then using it as the tables frame. I don't really understand that because I used 'mainScreen' as the frame for the parent view, but... like I said, I'm new to this stuff so I don't fully understand it. As a guess I think it has something to do with the fact that I have a navigation bar at the top, and it's using the size of the screen but the origin is under the navigation bar so it extends below the screen? Not fully sure, but I'd like to be able to fix the problem correctly instead of using 'magic numbers'...