1

First app, so every problem is new for me :-) I want to make a tab with instructions for my app. These instructions contain several points, so I wanted to make a static table and in each cell should be a textview containing some explanation text. The length however of this text is variable, since I make my app in two languages so I cannot use a defined height for each row or textview. But I don't want that the user to scroll each textview...they should be rather expanded fully so the only thing a user needs to scroll is the tableview.

I hope I explained it enough clearly...any hint how I could do that? I've tried some stuff in the interface builder, however everything remains quite static...

MichiZH
  • 5,587
  • 12
  • 41
  • 81
  • 1
    Given text to display, its possible to calculate the height. Check the link http://stackoverflow.com/questions/13086600/vary-table-view-cell-height-based-on-text. May b this helps. – iCoder Dec 03 '13 at 09:24

2 Answers2

1

What you could do is use lazy loading of your cellHeights array as explained in this link Best practices for drawing dynamic UITableView row height

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

        if ([cellHeights objectAtIndex:indexPath.row] == nil) {
            ... calculate height for your textview and store it in the array at the correct   index…


        }

        return [[cellHeights objectAtIndex:indexPath.row] floatValue];
}

or refer this link for another approach How can I do variable height table cells on the iPhone properly?

apple has nice example for mac for the same apple example

Community
  • 1
  • 1
Suhit Patil
  • 11,748
  • 3
  • 50
  • 60
0

If you are not expecting user input, then you should use UILabel to display text instead of UITextView. You can use auto layout features to adjust your UILabel to best fit your content.

You should check this documentation to get yourself familiar with auto layout.

mrt
  • 623
  • 4
  • 8
  • Yeah I'm not expecting user input. And I've used auto layout in my app (at least in interface builder) but I have no idea how to grow or shrink these labels and table cells? I mean I know how to change the constraints in code but how do I know the height the label or cell needs to be? – MichiZH Dec 03 '13 at 09:24
  • You can use sizeToFit or sizeThatFits: methods with UILabel. That way, you don't have to calculate the content size yourself. The view adjusts itself to fit its content. There is also content hugging and compression resistance priorities in interface builder, just above where constraints are for a view. You may check those as well. – mrt Dec 03 '13 at 09:34