3

iOS 7 用のサブビュー (スピナー付きのアラートビューによく似ています) を作成し、wimagguc の iOS 7 カスタムアラートビュー (git の ios-custom-alertview) を活用しました。ARCを使用。私が抱えている問題は、処理中にビューを表示し、処理が完了したら閉じるように呼び出しますが、まだ画面に表示されていることです。

Connection.m (編集)

 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");

    }

}

4

2 に答える 2

2

これは、インスタンス変数とプロパティ名の組み合わせが間違っているためです。私は個人的に自動生成@synthesizeメソッドを使用することはなく、クラスを次のように再コーディングします。

.h ファイル:

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

.m ファイル:

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

そして、すべての参照をaSpinnerCustomおよび およびにalertViewCustom変更します。非 ARC 環境ではインスタンス変数を直接参照しないでください。self.aSpinnerCustomself.alertViewCustom

あなたのコードで何が起こっているかというと、自動生成されたメソッドが、あなたが作成したものと一緒に で@synthesize始まるバッキング変数を作成したことです。_alertViewCustomself.alertViewCustom

また、オブジェクトを解放するためにdeallocメソッドを使用する必要があることを忘れないでください。self.whatever = nil;

于 2013-10-29T17:19:19.530 に答える