Center UITableViewCell

I notice that in most Apple programs using table views in grouped mode, the sections are vertically centered. For example, try editing an entry in the Contacts app. How would I go about achieving this effect in my own applications?

Anyone? I'm still looking for a solution to this problem. For now I'm just manually adjusting the height of the header, but I know there's got to be an easier way. For clarification on what I'm trying to do, look at the screenshot.

Ok, apparently I'm not too good at explaining myself. I meant that the cell usually defaults to the top of the screen. How would I set it so that it moves to the center?

Click to expand...

i understood what you were asking. that's interesting. i would have assumed that grouped tableviews would center vertically automatically. i'm using a plain tableview and set the contentInset manually depending on how many objects are in the datasource. would be nice if it could be done automatically, though.

OK, I misunderstood the question. I never really noticed that effect. In general you do want a textfield or textview to be visible above the keyboard but this doesn't happen automatically.

Either you need to set the contentOffsets or the frame of the table to center the row. The row will be flush to the top of the frame or the top contentOffset. Consider also what happens when the device is rotated.

UISearchDisplayController does this for its search bar and tables but otherwise I'm not aware of anything that does this automatically for other tables.

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.