简体   繁体   English

如何在iOS中调用UITableView的ScrollViewDidScroll委托方法

[英]How to call ScrollViewDidScroll delegate method of UITableView in IOS

I have a UITableView in that I am loading photos with comments.. 我有一个UITableView ,它可以加载带有评论的照片。

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. scrollviewDidScroll方法中,我有用于动态更新UITableviewCell的高度并显示注释的代码。 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.. 它应根据该照片的0或1或2或3条评论动态更新高度。

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. 但是scrollviewDidScroll没有调用。 If I scroll the table then only it is calling.. 如果我滚动表,那么只有它在调用。

Please suggest the ideas where I went wrong.. 请提出我错了的想法。

Thanks in Advance.. 提前致谢..

scrollviewDidScroll is a delegate method which is automatically called when the UITableView is scrolled. scrollviewDidScroll是一个委托方法,当滚动UITableView时会自动调用它。

If you want to scroll the UITableView , try and use this code : 如果要滚动UITableView ,请尝试使用以下代码:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:n inSection:0];
    [self.tableView scrollToRowAtIndexPath:indexPath
                    atScrollPosition:UITableViewScrollPositionTop
                            animated:YES];

As others have pointed out, you should not call your own delegate methods. 正如其他人指出的那样,您不应调用自己的委托方法。

This seems like an XY problem . 这似乎是一个XY问题

Take a step back and explain what you are trying to accomplish here. 退后一步,在这里说明您要完成的工作。 Why do you need your scrollviewDidScroll method to be called? 为什么需要调用scrollviewDidScroll方法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM