我的代码有什么问题吗?我正在使用 MBProgressHUD

发布于 2024-09-05 06:29:22 字数 1540 浏览 7 评论 0原文

我正在使用 MBProgress HUD,但我不知道问题出在哪里。 我有一个显示 HUDUIButton。 这是我的代码:

- (void)showHUD:(id)sender {
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    HUD.mode = MBProgressHUDModeCustomView;
    [self.view addSubview:HUD];
    HUD.delegate = self;
    HUD.labelText = @"No Internet Connection...";
    HUD.opacity = 0.7;
    HUD.customView = 
     [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
    [HUD showWhileExecuting:@selector(hudWasHidden) 
                   onTarget:self 
                 withObject:nil 
                   animated:YES];
}


- (void)hudWasHidden {

    float progress = 0.0f;
    while (progress < 1.0f) {
        progress += 0.01f;
        HUD.progress = progress;
        usleep(50000);
    }
}

这是控制台日志:

2010-06-11 17:55:26.255 Dual Search[14166:207] * -[MBProgressHUD setCustomView:]:
 unrecognized selector sent to instance 0x6321220 2010-06-11 17:55:26.256 Dual 
Search[14166:207] Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '** -[MBProgressHUD setCustomView:]: 
unrecognized selector sent to instance 0x6321220' 2010-06-11 17:55:26.256 Dual 
Search[14166:207] Stack: ( 41853515, 2505499913, 42125115, 41587990, 41584658, 
13036, 2853830, 3324117, 3332879, 3328066, 2977128, 2871789, 2903111, 49860988, 
41394236, 41390152, 49854621, 49854818, 2895329, 10508, 10362 )

单击 UIButton 时我的应用程序总是崩溃。

谢谢

I'm using MBProgress HUD and I don't know what is the problem.
I have a UIButton that shows the HUD.
This is my code:

- (void)showHUD:(id)sender {
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    HUD.mode = MBProgressHUDModeCustomView;
    [self.view addSubview:HUD];
    HUD.delegate = self;
    HUD.labelText = @"No Internet Connection...";
    HUD.opacity = 0.7;
    HUD.customView = 
     [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
    [HUD showWhileExecuting:@selector(hudWasHidden) 
                   onTarget:self 
                 withObject:nil 
                   animated:YES];
}


- (void)hudWasHidden {

    float progress = 0.0f;
    while (progress < 1.0f) {
        progress += 0.01f;
        HUD.progress = progress;
        usleep(50000);
    }
}

Here is the Console log:

2010-06-11 17:55:26.255 Dual Search[14166:207] * -[MBProgressHUD setCustomView:]:
 unrecognized selector sent to instance 0x6321220 2010-06-11 17:55:26.256 Dual 
Search[14166:207] Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '** -[MBProgressHUD setCustomView:]: 
unrecognized selector sent to instance 0x6321220' 2010-06-11 17:55:26.256 Dual 
Search[14166:207] Stack: ( 41853515, 2505499913, 42125115, 41587990, 41584658, 
13036, 2853830, 3324117, 3332879, 3328066, 2977128, 2871789, 2903111, 49860988, 
41394236, 41390152, 49854621, 49854818, 2895329, 10508, 10362 )

My app always crashes when clicking the UIButton.

Thanks

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

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

发布评论

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

评论(1

清眉祭 2024-09-12 06:29:22

这是 Cocoa 代码中常见的崩溃:在这种情况下“无法识别的选择器”非常明确。 MBProgressHUD 没有 customView 属性,尝试设置它会导致崩溃。 setCustomView 是这里调用的隐式选择器(方法),当调用的方法不存在时,Objective-C 将崩溃。

不知道该告诉您如何完成您想要做的事情。

This is a common crash in Cocoa code: "unrecognized selector" is very explicit in this case. MBProgressHUD doesn't have a customView property, and attempting to set it is causing the crash. The setCustomView is the implicit selector (method) being called here, and Objective-C will crash when a called method isn't there.

Not sure what to tell you about how to accomplish what you're trying to do.

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