我有一个表视图控制器,我正在添加一个加载视图(这是另一个UIView)。我将此加载视图作为子视图添加到tableview,然后将其删除。
我面临的问题是作为子视图添加的加载视图隐藏在部分标题下,并且在单元格上可见。
我该如何纠正?
我的代码添加了加载视图 -
@implementation RIDECustomActivityIndicator
- (id) initWithParentView:(UIView *)parentView withText:(NSString *)text{
self = [super init];
_parentView = parentView;
_loadingView = [[UIView alloc] initWithFrame:CGRectMake(75, 155, 170, 170)];
_loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
_loadingView.clipsToBounds = YES;
_loadingView.layer.cornerRadius = 10.0;
_activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_activityView.frame = CGRectMake(65, 40, _activityView.bounds.size.width, _activityView.bounds.size.height);
[_loadingView addSubview:_activityView];
_loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 115, 130, 22)];
_loadingLabel.backgroundColor = [UIColor clearColor];
_loadingLabel.textColor = [UIColor whiteColor];
_loadingLabel.adjustsFontSizeToFitWidth = YES;
_loadingLabel.textAlignment = NSTextAlignmentCenter;
_loadingLabel.text = text;
[_loadingView addSubview:_loadingLabel];
[_parentView addSubview:_loadingView];
[_loadingView setHidden:YES];
return self;
}
- (void) show {
[_activityView startAnimating];
[_loadingView setHidden:NO];
[_parentView setUserInteractionEnabled:NO];
}
- (void) hide {
[_activityView stopAnimating];
[_loadingView setHidden:YES];
[_parentView setUserInteractionEnabled:YES];
}
要初始化,我将表格视图作为parentView
传递,然后我可以show
和hide
。当parentView
是正常的UIView
时,这种情况很有效。