Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

manman

macrumors regular
Original poster
Aug 18, 2008
125
1
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.

Code:
{
	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

macrumors 6502a
Nov 9, 2007
733
6
Colchester, UK
It sounds like your tabie view isn't positioned in it's parent correctly.

Try changing:

Code:
initWithFrame:self.view.bounds

to:

Code:
initWithFrame:self.view.frame
 

manman

macrumors regular
Original poster
Aug 18, 2008
125
1
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

Code:
	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'...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.