gpt4 book ai didi

ios - 无法隐藏自定义 subview

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:49 26 4
gpt4 key购买 nike

我已经为 iOS 7 创建了一个 subview (看起来很像带微调器的警报 View ),并利用了 wimagguc 的 iOS 7 自定义警报 View (git 上的 ios-custom-alertview)。使用弧。我遇到的问题是我在处理时显示 View ,然后在处理完成时调用关闭,但仍在屏幕上显示。

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

}

最佳答案

这是因为您使用了错误的实例变量和属性名称组合。我个人从不使用自动生成的 @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;

然后将对 aSpinnerCustomalertViewCustom 的每个引用更改为 self.aSpinnerCustomself.alertViewCustom。切勿在非 ARC 环境中直接引用实例变量。

您的代码发生了什么是自动生成的 @synthesize 方法创建了以 _ 开头的支持变量,以及您创建的和使用 的支持变量有时 alertViewCustomself.alertViewCustom 有时使用了错误的对象引用。

并且不要忘记您的dealloc 方法应该使用self.whatever = nil; 来释放对象。

关于ios - 无法隐藏自定义 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19664708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com