0

I have a UITableView in that I am loading photos with comments..

I have horizontal scrolling of images in each row and vertical scrolling of users photos horizontally with comments..

I want to update the single cell when ever the user commented the photo.

At scrollviewDidScroll method I have code for dynamically updated the height of UITableviewCell and displaying the comments. As my requirement is dynamically increase height of custom cell with respect to comments of the photo scrolled. I am displaying latest three comments in the cell. It should dynamically updated the height based on 0 or 1 or 2 or 3 comments of that photo..

So, I have tried with below code..For updating the single row..

[self.photosTable beginUpdates];
[self.photosTable reloadRowsAtIndexPaths:[self.photosTable indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationAutomatic];
                    
[self.photosTable endUpdates];
                    
[self scrollViewDidScroll:self.photosTable];//As UITableView is sub class of UIScrollview I wrote like that

But scrollviewDidScroll is not calling. If I scroll the table then only it is calling..

Please suggest the ideas where I went wrong..

Thanks in Advance..

Vidhyanand
  • 5,369
  • 4
  • 26
  • 59
  • 1
    I wouldn't recommend calling delegate methods yourself. – Lord Zsolt Jun 27 '14 at 10:46
  • 1
    You can move the body if `scrollViewDidScroll:` into a method of yours, and call this from `scrollViewDidScroll:` and from the code snippet you've pasted above. However, I believe your problem is with something else. – Levi Jun 27 '14 at 10:58

2 Answers2

2

scrollviewDidScroll is a delegate method which is automatically called when the UITableView is scrolled.

If you want to scroll the UITableView, try and use this code :

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:n inSection:0];
    [self.tableView scrollToRowAtIndexPath:indexPath
                    atScrollPosition:UITableViewScrollPositionTop
                            animated:YES];
  • 1
    That would scroll the table view to the desired cell, but if you read the docs on that method they say: "Invoking this method does not cause the delegate to receive a scrollViewDidScroll: message, as is normal for programmatically-invoked user interface operations." – Duncan C Jun 27 '14 at 11:13
1

As others have pointed out, you should not call your own delegate methods.

This seems like an XY problem.

Take a step back and explain what you are trying to accomplish here. Why do you need your scrollviewDidScroll method to be called?

Community
  • 1
  • 1
Duncan C
  • 128,072
  • 22
  • 173
  • 272