Я использую ASIHTTPRequest для загрузки файла локально в iDevice.ASIHTTPRequest не обновляет делегата DownloadProgress
Мой скачать код выглядит следующим образом
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 значение по умолчанию для представления прогресса.
У кого-нибудь есть идея, что происходит?
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];
}
}
}
Это странно :) У вас нет двух UIProgressViews; один, созданный в xib (но не подключенный к IBOutlet) и один, созданный в коде (ваш 'progressDelegate')? – deanWombourne
На секунду я подумал, что пропустил что-то глупое, но и нет. UIProgressView (или мой подкласс) создается на xib. Я получаю доступ с помощью 'viewWithTag', поэтому там не должно быть проблем. –
Что вы можете получить, если вы добавите 'NSLog («% @ », [self superview]);' в вашем подклассе подпрограммы «setProgress:»? И, может быть, @Dirty Harrys ответ на что-то (хотя я подозреваю не потому, что ASI _should_ всегда выполняет обратные вызовы в основном потоке). – deanWombourne