gpt4 book ai didi

iphone - ASIHTTPRequest 没有更新 DownloadProgress 委托(delegate)

转载 作者:行者123 更新时间:2023-11-28 17:39:29 24 4
gpt4 key购买 nike

我正在使用 ASIHTTPRequest 将文件本地下载到 iDevice。

我的下载代码如下

ASIHTTPRequest *download = [ASIHTTPRequest requestWithURL: videoUrl];
[download setCompletionBlock:^{
NSLog(@"Download Success");
// other code
}];
[download setFailedBlock:^{
NSLog(@"Download Failed");
// other code
}];
[download setDownloadProgressDelegate: [item progressDelegate]];
[download startAsynchronous];
NSLog(@"Start Download of %@", [item name]);

对象 item 持有对 UIProgressView 的引用,它显示在屏幕上但从未更新。

为了调试,我继承了 UIProgressView 并添加了以下日志

- (void)setProgress:(float)newProgress {        
NSLog(@"Current Progress : %f", newProgress);
[super setProgress: newProgress];
}

我的控制台现在显示从 0.0 到 1.0 的进度超过 ~50 次迭代(很好!)但 uiProgressView 没有改变,最后 NSLog 显示 0.5 进度 View 的默认设置。

有人知道发生了什么事吗?

编辑使用此访问 UIProgressView

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath];
id progressView = [cell viewWithTag:VideoDetailProgressView];
[VideoDownloadManager queueDownloadOfVideo:video progressDelegate: progressView];
}

我已经逐步完成并观察到它似乎始终保持对 UIProgressView 的正确引用

编辑 TableView 方法

 // Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *detailCellIdentifier = @"VideoDetailCell";
static NSString *categoryCellIdentifier = @"VideoCategoryCell";
UITableViewCell *cell = nil;
bool isCategorical = [[self.videoList objectAtIndex: indexPath.row] objectForKey:@"parentName"];


if(isCategorical)
{
cell = [tableView dequeueReusableCellWithIdentifier:categoryCellIdentifier];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:detailCellIdentifier];
}

if (cell == nil && !isCategorical) {
[[NSBundle mainBundle] loadNibNamed:@"VideoDetailCell" owner:self options:nil];
cell = self.videoDetailCell;


UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5.0, 10.0, 46.0, 46.0)];
[cell addSubview:imageView];
imageView.hidden = !self.canEdit;
imageView.tag = VideoDetailsFavoriteButton;
[imageView release];


self.videoDetailCell = nil;
}
else if(cell == nil && isCategorical)
{
//Different cell
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:categoryCellIdentifier] autorelease];
}
[cell setBackgroundColor:[UIColor clearColor]];
return cell;
}



// Display customization
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *object = [self.videoList objectAtIndex:indexPath.row];
bool isCategorical = [[self.videoList objectAtIndex: indexPath.row] objectForKey:@"parentName"];

if(isCategorical) {
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.text = [object objectForKey:@"name"];

NSUInteger videoCount = [[Videos sharedVideos] countById: [object objectForKey:@"name"]];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.text = [NSString stringWithFormat: @"%d videos", videoCount];
}
else
{
[[cell viewWithTag:VideoDetailCellTitle] setValue:[object objectForKey:@"name"] forKey:@"text"];
[[cell viewWithTag:VideoDetailCellSubtitle] setValue:[object objectForKey:@"dateAdded"] forKey:@"text"];
[[cell viewWithTag:VideoDetailCellDuration] setValue:[object objectForKey:@"duration"] forKey:@"text"];

UIHTTPImageView *asyncImage = (UIHTTPImageView *)[cell viewWithTag:VideoDetailCellImage];
NSURL *thumbUrl = [NSURL URLWithString:[NSString stringWithFormat: @"%@%@", kRootUrlPath, [object objectForKey:@"image"]]];
[asyncImage setImageWithURL:thumbUrl placeholderImage: [UIImage imageNamed: kLoadingImage]];
asyncImage.clipsToBounds = YES;

UIImageView *editButton = (UIImageView *)[cell viewWithTag:VideoDetailsFavoriteButton];

if ([VideoDownloadManager isQueued: [object objectForKey: @"name"]]) {
[[cell viewWithTag:VideoDetailCellSubtitle] setHidden:YES];
[[cell viewWithTag:VideoDetailProgressView] setHidden:NO];
} else {
[[cell viewWithTag:VideoDetailCellSubtitle] setHidden:NO];
[[cell viewWithTag:VideoDetailProgressView] setHidden:YES];
}

if ([VideoDownloadManager isFavorites: [object objectForKey: @"name"]] || [VideoDownloadManager isQueued: [object objectForKey: @"name"]]) {
editButton.image = [UIImage imageNamed: kFavoritesHighlighted];
} else {
editButton.image = [UIImage imageNamed: kFavoritesEmpty];
}

}
}

最佳答案

你能检查更新是否在主线程中进行吗? (如果你使用的是最新版本的 ASIHTTPRequest,应该是这样的)

NSLog(@"Current Progress : %f (main thread=%d)", newProgress, [NSThread isMainThread]);

如果没有帮助,您可以显示在 View 中使用 UIProgressView 的代码吗?

关于iphone - ASIHTTPRequest 没有更新 DownloadProgress 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8731093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com