MBProgressHUD 崩溃“MBProgressHUD 初始化程序中使用的视图为零”
有人使用 MBProgressHUD 吗?我想在 MBProgressHUD librairie 提供的示例中使用动画 showWithLabelMixed。我将此代码从示例复制到我的项目中。
-(IBAction)showActivity:(id)sender
{
NSLog(@"Show Activity");
[self showWithLabelMixed];
}
- (void)showWithLabelMixed{
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Conecting";
HUD.minSize = CGSizeMake(135.f, 135.f);
[HUD showWhileExecuting:@selector(myMixedTask) onTarget:self withObject:nil animated:YES];
}
- (void)myTask {
// Do something usefull in here instead of sleeping ...
sleep(3);
}
- (void)myProgressTask {
// This just increases the progress indicator in a loop
float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
usleep(50000);
}
}
- (void)myMixedTask {
// Indeterminate mode
sleep(2);
// Switch to determinate mode
HUD.mode = MBProgressHUDModeDeterminate;
HUD.labelText = @"Progress";
float progress = 0.0f;
while (progress < 1.0f)
{
progress += 0.01f;
HUD.progress = progress;
usleep(50000);
}
// Back to indeterminate mode
HUD.mode = MBProgressHUDModeIndeterminate;
HUD.labelText = @"Cleaning up";
sleep(2);
// The sample image is based on the work by www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
HUD.mode = MBProgressHUDModeCustomView;
HUD.labelText = @"Completed";
sleep(2);
}
但我出了车祸
由于未捕获的异常而终止应用程序 'MBProgressHUDViewIsNillException',原因:'中使用的视图 MBProgressHUD 初始值设定项为零。' 你能帮我吗?
someone uses MBProgressHUD ? I want to use the animation showWithLabelMixed in the example provided with MBProgressHUD librairie. i copied this code from the exemple to my project .
-(IBAction)showActivity:(id)sender
{
NSLog(@"Show Activity");
[self showWithLabelMixed];
}
- (void)showWithLabelMixed{
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Conecting";
HUD.minSize = CGSizeMake(135.f, 135.f);
[HUD showWhileExecuting:@selector(myMixedTask) onTarget:self withObject:nil animated:YES];
}
- (void)myTask {
// Do something usefull in here instead of sleeping ...
sleep(3);
}
- (void)myProgressTask {
// This just increases the progress indicator in a loop
float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
usleep(50000);
}
}
- (void)myMixedTask {
// Indeterminate mode
sleep(2);
// Switch to determinate mode
HUD.mode = MBProgressHUDModeDeterminate;
HUD.labelText = @"Progress";
float progress = 0.0f;
while (progress < 1.0f)
{
progress += 0.01f;
HUD.progress = progress;
usleep(50000);
}
// Back to indeterminate mode
HUD.mode = MBProgressHUDModeIndeterminate;
HUD.labelText = @"Cleaning up";
sleep(2);
// The sample image is based on the work by www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
HUD.mode = MBProgressHUDModeCustomView;
HUD.labelText = @"Completed";
sleep(2);
}
But i have a crash
Terminating app due to uncaught exception
'MBProgressHUDViewIsNillException', reason: 'The view used in the
MBProgressHUD initializer is nil.'
can you help me please ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您初始化 HUD 的视图为零
尝试用以下命令初始化它
The view which you're initializing the HUD with is nil
Try initializing it with