Download progress in cell

时间秒杀一切 提交于 2019-12-04 20:45:30

You are right, due to cell re-use, it's not proper to connect each individual cell with download progress callback. To solve this, I will save download state in your Song object, when it's set to YES, start observing a notification.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(progressDidUpdate:) name:kSongDownloadProgressUpdateNotificaton object:nil];

in the progress call back block of AFHTTPRequestOperation, send out a name:kSongDownloadProgressUpdateNotificaton with a song id identifier.

in the progressDidUpdate: of individual cell, identify it's updating progress on itself, if not ignore it, if yes, update the progressView in the cell. When the downloading is finished, remove observation for the notification.

Additionally, you need to save a download percentage data in the Song object since when UITableView calls cellForRowAtIndexPath and Song will be assigned to another cell at any moment, saving and recovering progress will make the download state persistent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!