我真的坚持这个。 我们有一个IAP,其中列表视图是我们自己的,我们直接指向UADetailView进行购买。因此,我们没有进度条告诉用户下载的方式,我们的下载量很大。 我以为我可以使用MBProgressHud,但我遇到了一个问题。我似乎无法将UA的进展传递给HUD。如果我使用一个简单的计数器来计时,一切都可以正常使用HUD。就像他们自己的样本一样。
这是HUD电话;
- (void)showWithLabelDeterminate {
HUD = [[MBProgressHUD alloc] initWithView:self.view.window];
[self.view.window addSubview:HUD];
// Set determinate mode
HUD.mode = MBProgressHUDModeDeterminate;
HUD.delegate =self;
HUD.labelText = NSLocalizedString(@"DownLoading","");
// myProgressTask uses the HUD instance to update progress
[HUD showWhileExecuting:@selector(refreshProgress) onTarget:self withObject:nil animated:YES];
}
和我正在尝试使用的刷新;
- (void)refreshProgress:(float)progress {
while (progress < 1.0f)
NSLog(@"++ progress for HUD: %f", progress);
HUD.progress = progress;
}
然而,当我运行它时,应用程序崩溃了这个日志......
2012-01-30 12:23:18.838 isengua-en [12730:3827] - [UAProductDetailViewController refreshProgress]:无法识别的选择器发送到实例0x3e2c10 2012-01-30 12:23:18.840 isengua-en [12730:3827] *由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:' - [UAProductDetailViewController refreshProgress]:无法识别的选择器发送到实例0x3e2c10' * 第一次抛出调用堆栈:(0x30caa8bf 0x37e4f1e5 0x30cadacb 0x30cac945 0x30c07680 0x30c0922b 0xf4e59 0x37cbca91 0x37d505a1 0x36447c1d 0x36447ad8)终止调用抛出异常[
那里的人有同样的问题并解决了吗?
用chages更新......
- (void)showWithLabelDeterminate {
HUD = [[MBProgressHUD alloc] initWithView:self.view.window];
[self.view.window addSubview:HUD];
// Set determinate mode
HUD.mode = MBProgressHUDModeDeterminate;
HUD.delegate =self;
HUD.labelText = NSLocalizedString(@"DownLoading","");
// myProgressTask uses the HUD instance to update progress
[HUD showWhileExecuting:@selector(productsDownloadProgress:) onTarget:self withObject:nil animated:YES];
}
- (void)productsDownloadProgress:(float)progress count:(int)count {
HUD.progress = progress;
UALOG(@"[StoreFrontDelegate] productsDownloadProgress: %f count: %d", progress, count);
if (count == 0) {
NSLog(@"Downloads complete !");
}
}
并在购买按钮上
- (void)purchase:(id)sender {
self.navigationItem.rightBarButtonItem.enabled = NO;
[UAStoreFront purchase:product.productIdentifier];
[self.navigationController popViewControllerAnimated:NO];
[[UAStoreFront shared] setDelegate:self];
[self showWithLabelDeterminate];
}
崩溃日志:
2012-01-30 13:12:45.555 isengua-en [12886:6e27] - [UAProductDetailViewController productsDownloadProgress:]:无法识别的选择器发送到实例0x3f7f70 2012-01-30 13:12:45.557 isengua-en [12886:6e27] *终止应用程序 未捕获的异常'NSInvalidArgumentException',原因: ' - [UAProductDetailViewController productsDownloadProgress:]: 无法识别的选择器发送到实例0x3f7f70' * 第一次抛出调用堆栈:(0x30caa8bf 0x37e4f1e5 0x30cadacb 0x30cac945 0x30c07680 0x30c0922b 0xf5e21 0x37cbca91 0x37d505a1 0x36447c1d 0x36447ad8)终止调用抛出异常
答案 0 :(得分:1)
你的刷新进度方法需要一个参数(float),所以你的选择器的末尾应该有一个冒号:
在目标C中,这个:
@selector(refreshProgress:)
与此不一样:
@selector(refreshProgress)
它们是不同的方法名称。
答案 1 :(得分:1)
这里的崩溃非常清楚,尼克和肖恩已经对此进行了适当的解释。
更重要的问题是您正在为MBProgressHUD应用不正确的使用模式以进行下载操作。你应该做的是创建一个hud并在某种下载进程委托回调中更新它的进度。
您应该关注的示例是https://github.com/jdg/MBProgressHUD/blob/master/Demo/Classes/HudDemoViewController.m#L156,以及以下代理回调https://github.com/jdg/MBProgressHUD/blob/master/Demo/Classes/HudDemoViewController.m#L226。
答案 2 :(得分:0)
如果你有方法
- (void)productsDownloadProgress:(float)progress count:(int)count
然后它的选择器是
productsDownloadProgress:count:
不
productsDownloadProgress:
因此,通过给选择器“productsDownloadProgress:”而不是“productsDownloadProgress:count:”,您将为不存在的方法提供选择器。当HUD尝试调用该选择器时,Objective-C运行时在您指定的目标中查找它(在本例中为“self”),找不到它,并抛出NSInvalidArgument异常。
但是,即使您修复了无效的选择器问题,您仍可能会遇到麻烦。你的productsDownloadProgress:count:方法有两个参数,两个都是基本类型,但[HUD showWhileExecuting:onTarget:withObject:animated:]方法似乎想要一个只接受一个参数的选择器,该参数应该是一个Objective-C对象
这就是withObject:part的用途 - 你给它一个Objective-C对象,它将作为第一个参数传递给方法。
当然,我对Urban Airship一无所知,所以也许它会正常工作。