我用几个按钮构建了一个界面。这些按钮从互联网上获取信息以获取其标题。我为视图中的每个按钮添加了一个UIActivityIndicator,如下所示:
- (void) addActivityIndicator {
UIButton * button;
for (int i = 1; i <= 10; i++){
button = (UIButton *)[self viewWithTag:i];
NSLog(@"Button: %i",i);
[button setTitle:@"" forState:UIControlStateNormal];
button.enabled = NO;
UIActivityIndicatorView * buttonSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[buttonSpinner startAnimating];
buttonSpinner.tag = i;
buttonSpinner.frame = button.bounds;
[button addSubview:buttonSpinner];
}
}
但是,我似乎无法访问个别指标来删除它们。
[(UIButton *)[self viewWithTag:tag] setTitle:[NSString stringWithFormat:@"%@",[self addTitle:i]] forState:UIControlStateNormal];
[(UIButton *)[self viewWithTag:tag] setEnabled:YES];
[(UIButton *)[self viewWithTag:tag] [buttonSpinner stopAnimating]];
有什么想法吗?
答案 0 :(得分:1)
for (int i = 1; i <= 10; i++){
button = (UIButton *)[self viewWithTag:i];
NSLog(@"Button: %i",i);
[button setTitle:@"" forState:UIControlStateNormal];
button.enabled = NO;
UIActivityIndicatorView * buttonSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[buttonSpinner startAnimating];
buttonSpinner.tag = i*99;
buttonSpinner.frame = button.bounds;
[button addSubview:buttonSpinner];
}
然后,获取UIActivityIndicatorView
[(UIActivityIndicatorView *)[(UIButton *)[self viewWithTag:tag] viewWithTag:tag] stopAnimating];
答案 1 :(得分:-1)
也许您可以尝试迭代子视图并将其删除?
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIActivityIndicatorView *toRemove;
for (UIView *view in button.subviews)
{
if ([view isKindOfClass:[UIActivityIndicatorView class]])
{
toRemove = (UIActivityIndicatorView *)view;
break;
}
}
[toRemove removeFromSuperview];