Kostas
Kostas

Reputation: 377

Indicator within alert, indicator doesn't show up (resolved using UIAlertController)

I'm trying to follow the accepted solution from here on Xcode 6.3.2 but the indicator refuses to show up or I can't see it on my iPhone 6 plus for some reason. No error messages, the alert with the title, etc shows up and empty space.

What am I doing wrong? The alert is triggered after the connect button on the app is pressed...

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];

Upvotes: 0

Views: 1207

Answers (3)

Kostas
Kostas

Reputation: 377

After doing some further research and for anyone else interested in finding the solution in one spot (as there are parts in many other posts) I post the code that uses an UIAlertController (instead of a UIAlert), has an indicator and also the code for dismissal without the need for a button to be pressed.

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];

Upvotes: 2

Santu C
Santu C

Reputation: 2654

I was faced same issue in my one of project . I have resolved this in this way -

Define below in .h file

@property (strong, nonatomic) UIAlertView *alertViewProcessing;

.m file -

-(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];

}

Upvotes: 0

vikingosegundo
vikingosegundo

Reputation: 52237

from the docs

Subclassing Notes

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

Upvotes: 1

Related Questions