NSNotifcation 和异步下载帮助
我正在从一个视图向另一个视图发送通知。我的问题是,我在 cellForRowAtIndexPath 方法中调用的视图中的通知仅在表视图滚动时才会发送。我怎样才能阻止这个并让它在图像下载后发送通知?这是我的代码: https://gist.github.com/756302
谢谢
MKDev
I am sending a notification from one view to another view. My problem is that the notification in the view that I am calling in my cellForRowAtIndexPath method is only getting sent when the tableview is scrolling. How can I stop this and make it send the notification once the images have downloaded? Here is my code: https://gist.github.com/756302
Thanks
MKDev
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我了解您的代码,该消息将触发整个表的重新加载。这应该会导致单元格的刷新。
因此,您需要检查第 76 行,是否因为完成消息触发重新加载而正在绘制单元格(并且图像现在已准备好显示),或者是否需要开始图像的异步下载。
我想到检查这一点的第一件事是在 reloadTableView: 中设置一个属性,
然后添加
注意,重新加载表可能还有其他原因 - 视图可能已消失或卸载,而您可能不会希望多次触发异步加载。
as far as I understand your code, the message will trigger the reload of the whole table. That should lead to a refresh of the cells.
Thus, you'll need to check in line 76, if the cell is being drawn because a reload was triggered from the finish-message (and the image is now ready to display) or if you need to start the asynchronous download of the image.
The first thing which comes into my mind to check this is to set a property in reloadTableView:
and then to add in
Note that there could be other reasons why the table is being reloaded - the view could have been disappeared or unloaded and you might not wish to trigger your asynnchronous loading several times.
您的代码应该可以正常工作,当
connectionDidFinishLoading
时,您调用NSNotificationCenter
发送通知,cellForRowAtIndexPath
中没有 post 方法Your code should work right, when the
connectionDidFinishLoading
, you call theNSNotificationCenter
to send the notification, there is no post method incellForRowAtIndexPath