PDA

View Full Version : Center UITableViewCell




rstafford84
Jul 27, 2009, 06:00 PM
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?



rstafford84
Sep 6, 2009, 10:25 PM
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.

PhoneyDeveloper
Sep 6, 2009, 10:32 PM
UILabel automatically centers its text vertically. If you set the height of the label to the height of the cell that will do it.

Darkroom
Sep 6, 2009, 11:07 PM
does it not automatically center the row vertically (let's assume there is only 1) according to the height of the tableview?

rstafford84
Sep 6, 2009, 11:39 PM
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?

Darkroom
Sep 7, 2009, 12:01 AM
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?

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.

PhoneyDeveloper
Sep 7, 2009, 01:02 AM
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.

rstafford84
Sep 7, 2009, 12:59 PM
So either way I'd have to manually position it?

PhoneyDeveloper
Sep 7, 2009, 01:32 PM
Fraid so.

You need to get the size of the keyboard from the notifications that it posts when it appears. The keyboard size can vary depending on language chosen and device orientation.