How do I change the height of a UITableView to fit its dynamic content?

前端 未结 2 467
挽巷
挽巷 2021-01-20 05:46

I\'ve a UITableView which contains a cell, which in turn contains a TTTextEditor (a Three20 control) which for all intents and purposes is a UITextView. I\'m using the TTTex

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-20 06:10

    You need to set the contentSize not the frame. Calculate what the size SHOULD be, and then set it. This may require some calculation on your part. If you're dealing with text, then you may want to look at the method added to NSString called sizeWithFont:constrainedToSize:lineBreakMode:. Your frame, on the other hand, should always be the size of the viewable area, NOT the scrollable area.

    EDIT: Note that for the initial layouts that are not changing at that moment, you will probably want to use the standard table delegate mechanism of - (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath, but when that needs to change dynamically like this situation, I think adjusting the content size is worth a try.

提交回复
热议问题