如何在iOS7中删除UIButton
我想创建并删除uibutton。(第7章) My viewDidLoad函数按以下方式创建uibutton:如何在iOS7中删除UIButton,ios,objective-c,uibutton,Ios,Objective C,Uibutton,我想创建并删除uibutton。(第7章) My viewDidLoad函数按以下方式创建uibutton: for (char a = 'A'; a <= 'Z'; a++) { position = position+10; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@sele
for (char a = 'A'; a <= 'Z'; a++)
{
position = position+10;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(getByCharacter:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:[NSString stringWithFormat:@"%c", a] forState:UIControlStateNormal];
button.frame = CGRectMake(position, self.view.frame.size.height-40, 10.0, 10.0);
button.tintColor = [UIColor whiteColor];
[self.view addSubview:button];
}
我不知道怎么做。有人能提供一些示例代码吗?您可以通过调用
[sender removeFromSuperview];
在回调中(getByCharacter:)。将选择器连接到按钮时,
sender
参数将是触发事件的按钮。这意味着你有一个实例。使用此实例,您现在可以调用removeFromSuperview
方法。您可以通过调用
[sender removeFromSuperview];
在回调中(getByCharacter:)。将选择器连接到按钮时,
sender
参数将是触发事件的按钮。这意味着你有一个实例。在这个实例中,您现在可以调用removeFromSuperview
方法。首先需要获取按钮的标题文本,然后如果它与特定字符匹配,则将其从superView中删除
- (IBAction)getByCharacter:(id)sender{
UIButton *myButton = (UIButton *) sender;
if([myButton.titleLabel.text isEqualToString:@"C"]{
[myButton removeFromSuperView];
}
}
首先,您需要获取按钮的标题文本,然后将其从superView中删除(如果它与特定字符匹配)
- (IBAction)getByCharacter:(id)sender{
UIButton *myButton = (UIButton *) sender;
if([myButton.titleLabel.text isEqualToString:@"C"]{
[myButton removeFromSuperView];
}
}
[sender removeFromSuperview]
不够好吗?[sender removeFromSuperview]
不够好吗?