Question

I've created a subview (which looks a lot like an alertview with spinner) for iOS 7, and leveraged the iOS 7 custom alertview from wimagguc (ios-custom-alertview on git). Using ARC. The issue I have is I show the view while processing, then call to close when processing is complete, but is still showing on screen.

Connection.m (EDIT)

 UIActivityIndicatorView *aSpinnerCustom;
 CustomIOS7AlertView *alertViewCustom;

 - (void)showWaittingAlert:(BOOL)isShow {

NSString *ver = [[UIDevice currentDevice] systemVersion];
float ver_float = [ver floatValue];

// custom alert view for iOS 7 from AlertViewCustom folder
alertViewCustom = [[CustomIOS7AlertView alloc] init];

//spinner to be added to iOS 7 AlertView
aSpinnerCustom = [[UIActivityIndicatorView alloc]  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

//label to be used as subview to help text and spinner
alertTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 250, 75)];

//label of app name
UILabel *subTitleApp;
subTitleApp = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 250, 40)];
subTitleApp.text = APP_NAME;
subTitleApp.font = [UIFont boldSystemFontOfSize:16.0f];
subTitleApp.textAlignment = UITextAlignmentCenter;
subTitleApp.numberOfLines = 0;

//label of processing
UILabel *subTitle;
subTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, 250, 25)];
subTitle.text = @"processing...";
subTitle.font = [UIFont systemFontOfSize:14.0f];
subTitle.textAlignment = UITextAlignmentCenter;

//set height of spinner in custom alertview
aSpinnerCustom.frame = CGRectMake(round((alertTitle.frame.size.width - 25) / 2), round(alertTitle.frame.size.height - 30), 25, 25);
aSpinnerCustom.tag  = 1;

// adding text and spinner to alertview
[alertTitle addSubview:aSpinnerCustom];
[alertTitle addSubview:subTitleApp];
[alertTitle addSubview:subTitle];

//adding label to custom alertview
[alertViewCustom setContainerView:alertTitle];

[alertViewCustom setButtonTitles:NULL];

    if (isShow) {
        [alertViewCustom show];
        [aSpinnerCustom startAnimating];
        NSLog(@"%@",@"showWaitingAlert Show iOS 7");

    }else {
        [alertViewCustom close];
        [aSpinnerCustom stopAnimating];

        NSLog(@"%@",@"showWaitingAlert Stop iOS 7");

    }

}

Was it helpful?

Solution 2

Figured it out, my subview was created each time the method was called. I included an if alertview == nil so it wasn't created twice. Thanks @trojanfoe for your help as well.

 if (alertViewCustom == nil){
 setup view code here..
 }

OTHER TIPS

It's because you are using the wrong combination of instance variable and property names. I personally never use auto-generated @synthesize methods and would recode your class like this:

.h file:

@interface ConnectionManager : NSObject {
    UIActivityIndicatorView   *_aSpinnerCustom;
    CustomIOS7AlertView *_alertViewCustom;
}
@property (nonatomic, retain) UIActivityIndicatorView *aSpinnerCustom;
@property (nonatomic, retain) CustomIOS7AlertView *alertViewCustom;

.m file:

// Be explicit
@synthesize aSpinnerCustom = _aSpinnerCustom;
@synthesize alertViewCustom = _alertViewCustom;

and then change every reference to aSpinnerCustom and alertViewCustom to self.aSpinnerCustom and self.alertViewCustom. Never reference the instance variables directly in a non-ARC environment.

What's happening with your code is the auto-generated @synthesize methods have created backing variables starting with _, alongside the ones you created and as you use alertViewCustom sometimes and self.alertViewCustom at other times the wrong object references are being used.

And don't forget your dealloc method should use self.whatever = nil; in order to release the objects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top