是我的- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
代表我有以下代码:
if ([movie isDownloaded])
cell.detailTextLabel.text = movie.duration;
else
{
cell.detailTextLabel.text = @"";
[movie downloadInQueue:self.downloadQueue completion:^(BOOL success) {
UITableViewCell *updateCell = [tblView cellForRowAtIndexPath:indexPath];
if (updateCell)
{
updateCell.detailTextLabel.text = movie.duration;
[updateCell setNeedsLayout];
}
}];
}
调用 Movie.m 并运行以下代码:
- (void)downloadInQueue:(NSOperationQueue *)queue completion:(void (^)(BOOL success))completion
{
if (!self.isDownloading)
{
self.downloading = YES;
[queue addOperationWithBlock:^{
BOOL success = NO;
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:self.fileURL];
CMTime timeduration = playerItem.duration;
float seconds = CMTimeGetSeconds(timeduration);
self.duration = [self timeFormatted:seconds];
self.downloading = NO;
self.downloaded = YES;
success = YES;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
completion(success);
}];
}];
}
}
当我的单元格变得不NSOperation
可见时,Movie
如果对象尚未运行,我想取消它(将其从队列中删除)。我知道我可以继承UITableViewCell
并做这样的事情:
- (void)willMoveToWindow:(UIWindow *)newWindow
{
[super willMoveToWindow:newWindow];
if (newWindow==nil) {
// Cell is no longer in window so cancel from queue
}
}
问题......我如何Movie
NSOperation
从UITableViewCell
代表呼叫中取消我的?与代表或NSNotification
某种形式?我需要知道indexPath
单元格以从我的数组中获取正确的 Movie 对象并取消操作。