**在我的视图中单击按钮时,我需要两个文本字段和另一个按钮(删除)。如果我再次按下相同的动作重复最多5次。如果我单击删除按钮,则删除两个文本字段,并且文本字段下方必须出现*
-(IBAction)addBusiness:(id)sender
{
txtprovName2 = [[UITextField alloc]init];
[txtprovName2 setFrame:CGRectMake(13, 410,94, 30)];
[txtprovName2 setBorderStyle:UITextBorderStyleRoundedRect];
[txtprovName2 setAutocorrectionType:UITextAutocorrectionTypeNo];
txtprovName2.textAlignment=UITextAlignmentCenter;
txtprovName2.placeholder=@"";
txtprovName2.font=[UIFont fontWithName:@"System" size:11];
[testscroll addSubview:txtprovName2];
txtprovEmail2 =[[UITextField alloc]init];
[txtprovEmail2 setFrame:CGRectMake(121, 410,92, 30)];
[txtprovEmail2 setBorderStyle:UITextBorderStyleRoundedRect];
[txtprovEmail2 setAutocorrectionType:UITextAutocorrectionTypeNo];
txtprovEmail2.textAlignment=UITextAlignmentCenter;
txtprovEmail2.placeholder=@"";
txtprovEmail2.font=[UIFont fontWithName:@"System" size:11];
[testscroll addSubview:txtprovEmail2];
btnRemove1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnRemove1.frame = CGRectMake(220, 410,80, 30);
[btnRemove1 setTitle:@"Remove" forState:UIControlStateNormal];
[btnRemove1.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
btnRemove1.titleLabel.textColor=[UIColor blackColor];
[btnRemove1 addTarget:self
action:@selector(btnRemove1Clicked:)
forControlEvents:UIControlEventTouchUpInside];
}
如何继续为同一个按钮重复操作感谢帮助
答案 0 :(得分:7)
您可以使用按钮的tag属性;所以在你的IBAction方法中
- (IBAction)buttonClicked:(UIButton *)sender {
if (sender.tag == 1) {
// perform your 1st functionality
button.tag = 2; //To perform 2nd functionality
}
else if (sender.tag == 2) {
// perform your Second functionality
button.tag = 3; //To perform 3rd functionality
}
else if (sender.tag == 3) {
// perform your 3rd functionality
button.tag = 1; // To perform 1st functionality
}
}
修改强>
答案 1 :(得分:0)
只需按标签即可。你将节省大量的内存,并将正常工作。
答案 2 :(得分:0)
或者你可以使用这种方法..
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
&安培;稍后使用
- (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
这将解决您的问题。我希望。