rdu*_*and 5 iphone objective-c uialertview ios
我正在编写一个iOS应用程序,我必须使用微调器显示UIAlertView.有时,当我尝试在警报的中心添加微调器时出现问题,通常是在此之前有另一个警报(不完全是规则,但这是我注意到失败的方式).
我通过推迟创建微调器来部分解决了这个问题.我是这样做的(警报是成员UIAlertView):
此代码位于viewDidLoad中:
alert = [[[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
[self performSelector:@selector(addSpinner) withObject:nil afterDelay:0.5f];
Run Code Online (Sandbox Code Playgroud)
这个是我的addSpinner函数:
- (void) addSpinner{
UIActivityIndicatorView *indicator2 = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator2.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator2 startAnimating];
[alert addSubview:indicator2];
[indicator2 release];
}
Run Code Online (Sandbox Code Playgroud)
这个解决方案每次都在运行,但我真的不喜欢它是如何完成的.即使在警报弹出后半秒钟显示旋转器并不是那么令人不安,但必须有更好的方法来处理它.我不是iOS专家,也不是高级程序员,但我不能使用活动?像"实际显示警报时,转到addSpinner功能"这样的东西?我不知道怎么做,在网上找不到多少帮助......
希望可以有人帮帮我 !谢谢.
小智 5
您可以使用https://github.com/jdg/MBProgressHUD.
对于警报内的微调器,您可以使用这些方法.
-(void)startLoading
{
alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview:progress];
[progress startAnimating];
[progress release];
[alert show];
}
-(void)stopLoading
{
[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3644 次 |
| 最近记录: |