我需要能夠從視圖中刪除按鈕並添加一個不同的按鈕。我的代碼如下所示:removeFromSuperview不起作用
-(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確定檢查標記,但視圖不會被刪除。我應該提到我正在使用每5秒觸發一次updatepromobanner的線程。
請與小寫字母開始你的方法名。 – 2012-08-17 13:23:58