使用MBProgressHUD断言失败 - 视图不能为零

Stu*_*rtM 12 uiviewcontroller uiview ios mbprogresshud ios5

我试图MBProgressHUD在一个应用程序中使用.我将HUD添加到视图中时出错.

这是将进度条添加到视图的代码.

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];
Run Code Online (Sandbox Code Playgroud)

应用程序错误:

*** Assertion failure in -[MBProgressHUD initWithView:], /Users/.../MBProgressHUD/MBProgressHUD.m:190
Run Code Online (Sandbox Code Playgroud)

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'View must not be nil.'
Run Code Online (Sandbox Code Playgroud)

Crash: View must not be nil.
Run Code Online (Sandbox Code Playgroud)

有谁知道断言失败是什么以及如何解决.MBProgressHUD.m文件包含在Build Phases选项卡下的Compile Sources中,并包含在文件中.正在将进展添加到处理现场验证的过程中.

Coc*_*aEv 17

您好,这是HUD显示屏的快速提示.

首先,不要试图在这里翻转,但要确保如果您正在为导航控制器初始化HUD,那么您有一个 - 或其他任何事情.请注意,在视图中粘贴HUD越高,HUD叠加层将禁用和覆盖的交互越多(通常这是一件好事).

例如,如果您在基本视图控制器或模态等中执行以下操作:

HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
Run Code Online (Sandbox Code Playgroud)

请注意,您要将其添加到初始化它的同一视图中.

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

我认为如果您使用正确的应用程序视图关注init示例,您的问题将自行解决.

好吧