iPhone - having selected cell move to top of uitableview

Alex Muller picture Alex Muller · Mar 18, 2011 · Viewed 8.4k times · Source

I looked for this problem and I don't believe I could find an answer. I have a tableview of custom cells that when clicked, the selected cell pushes a new cell with information. I was wondering if anyone had an idea of how to push the selected cell to the top of the uitableview, or make it fill up the entire tableview.

My uitableview only takes up half of the screen, and I wish for when the cell is selected that it only take up that half of the screen, and the user is still able to scroll the cell (if that makes sense)?

Any suggestions would be appreciated, it was somewhat difficult to describe what I am looking for, so if anyone needs clarification please do not hesitate to ask me.

Answer

Alex Muller picture Alex Muller · Mar 22, 2011

in cellForRowAtIndexPath, you need to place this in after you have created your cell

    [tableView scrollToRowAtIndexPath:selectedCellIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

This did the trick for me with the custom height of the cells as well.