ビューからボタンを削除し、別のボタンを追加する必要があります。私のコードは次のようになります: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のokを押すが、ビューは削除されない。私は、5秒ごとにupdatepromobannerを起動するスレッドを使用していることを言及する必要があります。
は小文字を使用してメソッド名を起動してください。 –