0

我真的坚持这个。我们有一个 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] * 终止app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UAProductDetailViewController refreshProgress]: unrecognized selector sent to instance 0x3e2c10' * First throw call stack: (0x30caa8bf 0x37e4f1e5 0x30cadacb 0x30cac945 0x30c07680 0x30c0922b 0xf4e59 0x37cbca91 0x37d505a1 0x36447c1d 0x36447ad8) terminate called throwing an exception[

有谁遇到过同样的问题并解决了吗?

更新费用...

- (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] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UAProductDetailViewController productsDownloadProgress:]: unrecognized selector sent to instance 0x3f7f70' * First throw call stack: (0x30caa8bf 0x37e4f1e5 0x30cadacb 0x30cac945 0x30c07680 0x30c0922b 0xf5e21 0x37cbca91 0x37d505a1 0x36447c1d 0x36447ad8) terminate called throwing an例外

4

3 回答 3

1

您的刷新进度方法需要一个参数 (float),因此您的选择器末尾应该有一个冒号:

在目标 C 中,这:

@selector(refreshProgress:)

和这个不一样:

@selector(refreshProgress)

它们是不同的方法名称。

于 2012-01-30T12:48:35.753 回答
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

于 2012-03-14T11:11:50.157 回答
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: 部分的用途——你给它一个 Objective-C 对象,它将作为它的第一个参数传递给方法。

当然,我对Urban Airship一无所知,所以也许它会很好用。

于 2012-02-09T21:01:28.183 回答