views:

134

answers:

3

In RootViewController am using a UITableView for displaying the content of data. In the didSelectRowAtIndexPath method, I am calling another view controller (DetailViewController) to display detailed data. For displaying this detailed data I am using a UITableview in the DetailViewController also. This table contains one section and only one row.

Now the problem is that I have to adjust the table's height dynamically when I move from RootViewController to DetailViewController. How can I make the height of the UITableView dynamic between the two classes?

Any help would be Appreciated!

+4  A: 

You can implement the UITableViewDelegate method something like:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   return [TextToDisplay sizeWithFont:/*DESIRED_FONT*/ constrainedToSize:/*YOUR DESIRED_SIZE*/ lineBreakMode:/*DESIRED_LINEBREAKMODE*/].height;
}

to get variable heights.

Prakash
+1  A: 

It sounds like your trying to reuse a UITableView between two different UIViewControllers. I think your better off having the RootViewController have it's own UITableView which is set to a dynamic height and width using the UIView autoresizingMask property. Then when you select a row and push on the DetailViewController in a UINavigationController stack it would have it'd own UITableView to display the detail information your trying to show.

This interaction technique is used throughout other iPhone applications like Mail. If I misunderstood your question please let me know.

Sean
A: 

To Prakash:

Would please give an example for /*DESIRED_FONT*/ /*YOUR DESIRED_SIZE*/ and /*DESIRED_Linebreakmode*/

/ - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode

I don't know how to replace font, size and lineBreakMode.

Jens Koehler