views:

301

answers:

2

Hi all,

thanks to the folks here I already learned quite a lot on my way to a cool iPhone App I am working on. However, I was wondering if anyone found out how to manipulate a UITableView, so that a cell (any or, if that is not possible, it could only be the selected one) can have a different height.

I know I can use something like this:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 70;

}*/

To modify the whole TableView. But how would I address this to a single, specific cell?

The final goal is to achieve a "OS X dock"-like zoom effect when scrolling through a table...

Any help is appreciated.

Best regards, J*

A: 

You use the indexPath row and section to determine and return the height for the cell.

All of the methods related to UITableViewController give you an indexPath that will correspond to the cell when asking for specific information. For example, when asking for the actual cell to return: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

What to do when a cell was selected: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Height of the cell: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

And several others. Check out a UITableViewController tutorial to get the hang of how it works as a delegate and a dataSource for a UITableView.

Here is a good one: http://adeem.me/blog/2009/05/19/iphone-programming-tutorial-part-1-uitableview-using-nsarray/

mjdth
Hi mjdth,thanks a lot ... I guess getting used to the general approach of Cocoa and OOP is my issue here. I will try to find that how to do smthg with NSIndexPath and the method to set the height. Thanks for the link to the tutorial.
Jondalar
+1  A: 

The method that you're citing there in your question is exactly the method you want to use. The code you posted always returns a fixed value. But the indexPath parameter is there so that you can use that in whatever conditional processing you might want to do. For example, determine if that row is selected, and return a different height.

You'll also want to take care that the cell you return from -[UITableView cellForRowAtIndexPath:] matches this height.

Sixten Otto