我试图按照here在Xcode 6.3.2上接受的解决方案,但该指示器拒绝显示,或者由于某种原因我无法在iPhone 6 plus上看到它。没有错误消息,带有标题的警报等显示空白空间。
我做错了什么?按下应用程序上的连接按钮后触发警报...
UIAlertView *alertWithInd;
UIActivityIndicatorView *alertInd;
alertWithInd = [[UIAlertView alloc] initWithTitle:@"Connecting..." message:@"Please wait...\n\n\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
alertInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
alertInd.frame=CGRectMake(0, 20, 270, 100);
[alertInd startAnimating];
[alertWithInd addSubview:alertInd];
[alertWithInd show];
答案 0 :(得分:2)
在做了一些进一步的研究之后,对于任何有兴趣在一个地方找到解决方案的人(因为在许多其他帖子中都有部分)我发布了使用UIAlertController(而不是UIAlert)的代码,有一个指标,还有解雇代码,无需按下按钮。
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"Connecting"
message:@"Please wait...\n\n"
preferredStyle:UIAlertControllerStyleAlert];
UIActivityIndicatorView *alertInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
alertInd.frame=CGRectMake(0, 40, 270, 100);
[alertInd startAnimating];
[alertController.view addSubview:alertInd];
id rootViewController=[UIApplication sharedApplication].delegate.window.rootViewController;
if([rootViewController isKindOfClass:[UINavigationController class]])
{
rootViewController=[((UINavigationController *)rootViewController).viewControllers objectAtIndex:0];
}
[rootViewController presentViewController:alertController animated:YES completion:nil];
// to dismiss the alert with no button use:
[alertController dismissViewControllerAnimated:YES completion:nil];
答案 1 :(得分:1)
答案 2 :(得分:0)
我的项目中遇到了同样的问题。我已经用这种方式解决了这个问题 -
在.h文件中定义以下
@property (strong, nonatomic) UIAlertView *alertViewProcessing;
.m文件 -
-(void)processing
{
self.alertViewProcessing = [[UIAlertView alloc] initWithTitle:@"Requesting...." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator startAnimating];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 40.0, 40.0)];
view.backgroundColor =[UIColor clearColor];
indicator.frame = CGRectMake(120.0, 0.0, 20.0, 20.0 );
[view addSubview:indicator];
[self.alertViewProcessing setValue:view forKey:@"accessoryView"];
}
else
{
[self.alertViewProcessing setValue:indicator forKey:@"accessoryView"];
}
[self.alertViewProcessing show];
}