Center UITableViewCell

Discussion in 'iOS Programming' started by rstafford84, Jul 27, 2009.

  1. rstafford84 macrumors newbie

    Joined:
    Jul 17, 2009
    #1
    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?
     
  2. rstafford84 thread starter macrumors newbie

    Joined:
    Jul 17, 2009
    #2
    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.
     

    Attached Files:

  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    UILabel automatically centers its text vertically. If you set the height of the label to the height of the cell that will do it.
     
  4. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #4
    does it not automatically center the row vertically (let's assume there is only 1) according to the height of the tableview?
     
  5. rstafford84 thread starter macrumors newbie

    Joined:
    Jul 17, 2009
    #5
    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?
     

    Attached Files:

  6. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #6
    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.
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    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.
     
  8. rstafford84 thread starter macrumors newbie

    Joined:
    Jul 17, 2009
    #8
    So either way I'd have to manually position it?
     
  9. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    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.
     

Share This Page