Sam
Sam

Reputation: 2331

UITableView with dynamic height

My project is posted on Github. Before running the app, you need to start a server by going to the directory VideoTutorialsWithServerApp/nodeServerand running node server.js from the command line.


I have a feature where comments can be added to the videos on the app by entering a name and comment into the spot that says Leave a comment. The comments appears after clicking back and visiting the video again. It appears the table view can only be the size of max three comments however. In the picture below, there should be 4 comments but there are only 3. I've tested this and the max is always 3 comments for any video.

enter image description here

You can view the comments that should be displayed for table 1 by visiting 'http://localhost:6060/comments/1'

[{"user":"Sam","comment":"First Comment"},{"user":"Kailee","comment":"First Second Comment"},{"comment":"Third Comment","user":"Sam"},{"comment":"Fourth Comment","user":"Sam"}]

I think it's because there's a set height for the uitableview, I don't know how to set the height to be dynamic. The height for each of the cells is also dynamic based on the text that is in the cells.


Just about there,

So all the comments show up now, but the scroll view rests in the middle of the bottom comment, so that only the name of the last comment is visible unless the user is actively pushing the screen up to see the last comment.

enter image description here

Upvotes: 1

Views: 276

Answers (1)

Hitesh Borse
Hitesh Borse

Reputation: 479

You need to use intrinsicContentSize variable of a UITableView. intrinsicContentSize will give us table height.

Create a subclass for child tableView and override intrinsicContentSize.

Dynamic row heights of a UITableView inside a UITableViewCell

Upvotes: 2

Related Questions