나는이 긴 질문에 대해 매우 사과드립니다.이상한 충돌로 끝나는 MBProgressHUD에 데이터를 전달하는 사람
내 앱에서 큰 동영상 파일 (30-60Mb)을 다운로드합니다. 분명히 사용자에게 진행 상황을 알리고 싶습니다. 다운로드는 Urban Airship에서 진행되었으며 진행 방법을 얻으려는 방법 중 하나를 사용합니다. 그러나 이것은 TableViewController에서 발생하지만 다운로드 표시기 (MBProgressHUD)는 다른보기에서 시작하여 UADetail이라고합니다.
하나의보기에서 다른보기로 진행률을 전달하려면 Singleton을 사용합니다. 무작위로, 일찍, 늦게 또는 전혀 일어나지 않을 수 있습니다. 앱이 로그와 함께 충돌합니다.
2012-03-12 15 : 13 : 30.528 isengua 엔 [3478 : 681f] lessonDownloadProgress HUD : 0.053478 2012-03-12 15 : 13 : 30.553 isengua 엔 [3478 : 707] Lessonlist 진행 : 0.055272 2012-03-12 15 : 13 : 30.562 isengua-ko [3478 : 707] LLVC downHUD 진행률 : 0.055272 2012-03-12 15 : 13 : 30.565 isengua-en [3478 : 707] - [LessonListViewController> 제품 다운로드 진행률 : 개수 :] [줄 57] [StoreFrontDelegate] 제품 다운로드 진행 : 0.055272 개수 : 1 2012-03-12 15 : 13 : 30.569 isengua-ko [3478 : 6307] * - [CFNumber _getValue : forType :] : 할당 취소 된 인스턴스 0x83c6e80
먼저 LessonListViewController입니다.
- (void)productsDownloadProgress:(float)progress count:(int)count
{
DataManager *sharedManager = [DataManager sharedManager];
sharedManager.downHUD = [NSNumber numberWithFloat:progress];
NSLog(@"Lessonlist progress: %f", progress);
NSLog(@"LLVC downHUD progress: %f", [sharedManager.downHUD floatValue]);
UALOG(@"[StoreFrontDelegate] productsDownloadProgress: %f count: %d", progress, count);
if (count == 0) {
NSLog(@"Downloads complete in LessonListView!");
}
}
싱글 톤은 다음과 같습니다;
@implementation DataManager
@synthesize downHUD;
+ (DataManager *)sharedManager
{
static DataManager *sharedManager = nil;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
sharedManager = [[self alloc] init];
});
return sharedManager;
}
- (id)init {
if (self = [super init]) {
downHUD = [NSNumber numberWithFloat:(float)0];
}
return self;
}
- (void)dealloc {
// Should never be called, but just here for clarity really.
NSLog(@"dealloc called in DataManager");
}
@end
그리고는 다음 UADetail 읽어 얻을;
- (void)showWithLabelDeterminate {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
// Set determinate mode
HUD.mode = MBProgressHUDModeIndeterminate;
HUD.delegate = self;
HUD.labelText = NSLocalizedString(@"Waiting","");
// myProgressTask uses the HUD instance to update progress
[HUD showWhileExecuting:@selector(lessonDownloadProgress) onTarget:self withObject:nil animated:YES];
}
-(void)lessonDownloadProgress
{
DataManager *sharedManager = [DataManager sharedManager];
HUD.mode = MBProgressHUDModeDeterminate;
HUD.progress = [sharedManager.downHUD floatValue];
HUD.labelText = NSLocalizedString(@"DownLoading","");
while (HUD.progress < 1)
{
[self parentViewController];
NSLog(@"HUD lessonDownloadProgress: %f", HUD.progress);
HUD.progress = [sharedManager.downHUD floatValue];
NSString *percent = [NSString stringWithFormat:@"%.0f", HUD.progress/1*100];
HUD.detailsLabelText = [percent stringByAppendingString:@"%"];
}
}