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

rstafford84

macrumors newbie
Original poster
Jul 17, 2009
16
0
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

macrumors newbie
Original poster
Jul 17, 2009
16
0
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.
 

Attachments

  • tableview.png
    tableview.png
    212.5 KB · Views: 87

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
UILabel automatically centers its text vertically. If you set the height of the label to the height of the cell that will do it.
 

rstafford84

macrumors newbie
Original poster
Jul 17, 2009
16
0
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?
 

Attachments

  • default.png
    default.png
    211.5 KB · Views: 73

Darkroom

Guest
Dec 15, 2006
2,445
0
Montréal, Canada
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

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.