iOS 城市飞艇进度和 HUD

发布于 2024-12-29 23:05:26 字数 3066 浏览 1 评论 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刷新进度]:无法识别的选择器发送到实例0x3e2c10 2012-01-30 12:23:18.840 isengua-en[12730:3827] * 由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[UAProductDetailViewController freshProgress]:无法识别的选择器发送到实例 0x3e2c10' *第一次抛出调用堆栈:(0x30caa8bf 0x37e4f1e5 0x30cadacb 0x30cac945 0x30c07680 0x30c0922b 0xf4e59 0x37cbca91 0x37d505a1 0x36447c1d 0x36447ad8) 终止调用抛出异常[

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

更新更改...

- (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) 终止调用抛出异常

I'm really stuck on this one.
We have an IAP where the list view is our own and we point directly to the UADetailView for purchasing. Because of this we don't have a progress bar to tell the user how the download is going, and our downloads are big.
I thought I could use the MBProgressHud, but I have run into a problem. I don't seem to be able to pass the progress from UA to the HUD. Everything works fine with the HUD if I use a simple counter to clock it up. Much as their own sample.

Here is the HUD call;

- (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];

}

and the refresh that I'm trying to use;

- (void)refreshProgress:(float)progress {
   while (progress < 1.0f)
    NSLog(@"++ progress for HUD: %f", progress);
  HUD.progress = progress;

}

However, when I run it the app crashes with this log...

2012-01-30 12:23:18.838 isengua-en[12730:3827]
-[UAProductDetailViewController refreshProgress]: unrecognized selector sent to instance 0x3e2c10 2012-01-30 12:23:18.840
isengua-en[12730:3827] * Terminating 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[

Anyone out there that has had the same problem and solved it?

Update with 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 !");

    }
}

and this on the purchase button

- (void)purchase:(id)sender {
self.navigationItem.rightBarButtonItem.enabled = NO;
[UAStoreFront purchase:product.productIdentifier];         
[self.navigationController popViewControllerAnimated:NO];
[[UAStoreFront shared] setDelegate:self];
[self showWithLabelDeterminate];

}

Crash log:

2012-01-30 13:12:45.555 isengua-en[12886:6e27]
-[UAProductDetailViewController productsDownloadProgress:]: unrecognized selector sent to instance 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 exception

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何其悲哀 2025-01-05 23:05:26

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

在目标 C 中,这:

@selector(refreshProgress:)

与此不同:

@selector(refreshProgress)

它们是不同的方法名称。

Your refresh progress method takes a parameter (float) so your selector should have a colon on the end:

In objective C, this:

@selector(refreshProgress:)

Is not the same as this:

@selector(refreshProgress)

They are different method names.

折戟 2025-01-05 23:05:26

这里的崩溃非常清楚,并且已经由尼克和肖恩进行了适当的解释。

更重要的问题是您为下载操作应用了不正确的 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

The crashes here are pretty clear and have been appropriately explained by Nick and Sean.

The more important problem is that you're applying an incorrect usage pattern for MBProgressHUD for a download operation. What you should be doing is creating a hud and updating it's progress in some sort of download progress delegate callback.

The example you should be looking at is https://github.com/jdg/MBProgressHUD/blob/master/Demo/Classes/HudDemoViewController.m#L156 , together with the following delegate callbacks https://github.com/jdg/MBProgressHUD/blob/master/Demo/Classes/HudDemoViewController.m#L226.

就是爱搞怪 2025-01-05 23:05:26

如果您有一个方法

- (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 对象,它将作为第一个参数传递给该方法。

当然,我对城市飞艇一无所知,所以也许它会工作得很好。

If you have a method

- (void)productsDownloadProgress:(float)progress count:(int)count

then its selector is

productsDownloadProgress:count:

not

productsDownloadProgress:

So, by giving the selector "productsDownloadProgress:" instead of "productsDownloadProgress:count:" you are giving a selector to a method that doesn't exist. When HUD tries to call that selector, the Objective-C runtime looks for it in the target you specified ("self" in this case), can't find it, and throws an NSInvalidArgument exception.

You will probably still have trouble, though, even if you fix the invalid selector problem. Your productsDownloadProgress:count: method takes two arguments, both of which are basic types, yet the [HUD showWhileExecuting:onTarget:withObject:animated:] method seems to want a selector that only takes one argument and that argument should be an Objective-C object.

That's what the withObject: part is for -- you give it an Objective-C object and it will get passed to the method as its first argument.

Of course, I don't know anything about Urban Airship, so maybe it will work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文