作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人使用 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);
}
但是我发生了崩溃
Terminating app due to uncaught exception 'MBProgressHUDViewIsNillException', reason: 'The view used in the MBProgressHUD initializer is nil.' can you help me please ?
最佳答案
您用来初始化 HUD 的 View 为零尝试初始化它
[[UIApplication sharedApplication] keyWindow]
关于iphone - MBProgressHUD 崩溃 "The view used in the MBProgressHUD initializer is nil",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8258703/
我是一名优秀的程序员,十分优秀!