我需要能够从视图中删除一个按钮并添加一个不同的按钮。我的代码如下所示:
-(void)UpdatePromoBanner:(NSString*)value{
[button setTitle:@"newer text" forState:UIControlStateNormal];
for (UIView *subView in emptyViewController.view.subviews)
{
if(subView.tag == 99) {
//--remove button and add an updated one
NSLog(@"Remove button?");
[subView removeFromSuperview];
//[subView.superview addSubview:button];
}
}
NSLog(@"event called");
}
-(void)AddPromoBannerToBottom:(UIView*)view {
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:lblForBannerButton forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
button.tag = 99;
[view addSubview:button];
}
emptyViewController 只是一个普通的空视图控制器。我在中间添加一个按钮。我点击了检查标签的 NSLog ok,但视图没有被删除。我应该提到我正在使用每 5 秒触发一次 updatepromobanner 的线程。