我正在使用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];
}
我的控制台现在显示在50次迭代中从0.0到1.0的进度(很好!)但是uiProgressView没有改变,最后NSLog显示0.5进度视图的默认设置。
任何人都知道发生了什么事?
EDIT 使用此
访问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];
}
}
}
答案 0 :(得分:0)
您可以检查是否在主线程中进行了更新吗? (如果您使用的是最新版本的ASIHTTPRequest,应该是这种情况)
NSLog(@"Current Progress : %f (main thread=%d)", newProgress, [NSThread isMainThread]);
如果它没有帮助,你能在视图中显示使用UIProgressView的代码吗?
答案 1 :(得分:0)
感谢大家的帮助。你们引导我回答。我的单元格未正确分配了reuseIdentifier
这导致了整个问题。