1

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

Sam
  • 1,765
  • 11
  • 82
  • 176
  • use UITableViewAutomaticDimension to give height of cells. It do the dynamic heights. Also, don't forget to set estimateHeight and rowHeight of table in ViewDidLoad. – Kamal Bhardwaj Oct 10 '19 at 08:06
  • @KamalBhardwaj Where do I use that? – Sam Oct 10 '19 at 08:10
  • in your project, height of TopInScrollView is alway = scrollview's height and = self.view.frame.size.height. Because you not set height for comment tableview while UITableview can not auto resize (just uitableviewcell can automatic height and uitablebview 'll update contentsize not size). So you have to calculate commentTableview's required height , add height contraint for commentTableview and change it in your code – Nguyen Hoan Oct 10 '19 at 08:49
  • @NguyenHoan How can I calculate each table cells height? I'm pretty new to Obj-c, so I'm thinking I could loop through the cells in the table and add the height of each cell to the table height, but I'm not sure what to add together, and I'm not sure where to add it (maybe the line after [self updateTableData]; ?) – Sam Oct 10 '19 at 09:41
  • 1- you can reload tableview -> delay a second => get contensize-> update height contrains. 2- get height of comment cell : https://stackoverflow.com/questions/2669063/how-to-get-the-size-of-a-nsstring – Nguyen Hoan Oct 10 '19 at 09:47
  • But i think you should use only 1 tableview for all your content - with webview is header of tableview, anything else 's uitableviewcell or header of section – Nguyen Hoan Oct 10 '19 at 09:49
  • @NguyenHoan Where is the contentsize stored. I know it might be obvious to you, but because the delegate functions are creating the cells I don't really know how to access them except within the `willDisplayCell` and `cellForRowAtIndexPath` functions – Sam Oct 10 '19 at 09:51

1 Answers1

2

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

Hitesh Borse
  • 479
  • 2
  • 12
  • Thanks, your solution is almost perfect, I posted an update because there's still a small problem with the app. – Sam Oct 10 '19 at 13:03
  • I ended up just modifying to the constraint to have a constant of 50 – Sam Oct 10 '19 at 13:57