gpt4 book ai didi

ios - 使用 MBProgressHUD 的断言失败 - View 不能为 nil

转载 作者:技术小花猫 更新时间:2023-10-29 10:34:33 26 4
gpt4 key购买 nike

我正在尝试在应用程序中使用 MBProgressHUD。我在将 HUD 添加到 View 时遇到错误。

这是将进度条添加到 View 的代码。

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.view.window addSubview:HUD];

// Set determinate mode
HUD.mode = MBProgressHUDModeAnnularDeterminate;

HUD.labelText = @"Loading";

// myProgressTask uses the HUD instance to update progress
[HUD showWhileExecuting:@selector(processFieldEntries) onTarget:self withObject:nil animated:YES];

应用程序错误:

*** Assertion failure in -[MBProgressHUD initWithView:], /Users/.../MBProgressHUD/MBProgressHUD.m:190

还有

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'View must not be nil.'

Crash: View must not be nil.

有谁知道断言失败的原因以及如何解决。 MBProgressHUD.m 文件包含在 Build Phases 选项卡下的 Compile Sources 中,文件中包含 header 。正在将进度添加到处理字段验证的过程中。

最佳答案

您好,这是关于 HUD 显示的快速提示。

首先,不要试图在这里翻转,但请确保如果您正在为导航 Controller 初始化 HUD,那么您有一个 - 或任何其他与此相关的东西。请注意,您将 HUD 贴在 View 中的位置越高,HUD 覆盖层禁用和覆盖的交互就越多(这通常是一件好事)。

例如,如果您在基本 View Controller 或模式等中执行以下操作:

HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];

请注意,您正在将其添加到与初始化它相同的 View 中。

另请注意,您也可以将其填充到其他 View 中,例如:self.navigationcontroller.view、self.splitviewcontroller.view 或我最喜欢的:self.splitviewcontroller.view.superview(覆盖和禁用 View 的两侧)。

我认为如果您按照 init 示例使用正确的应用 View ,您的问题会自行解决。

祝你好运。

关于ios - 使用 MBProgressHUD 的断言失败 - View 不能为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12149922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com