gpt4 book ai didi

iphone - iPhone 中单个 UIButton 的多个操作

转载 作者:行者123 更新时间:2023-12-03 18:54:32 25 4
gpt4 key购买 nike

** 当在我的 View 中单击按钮时,我需要两个文本字段和另一个按钮(删除)。如果我再次按下相同的操作,最多会重复 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];

}

我如何继续对同一按钮进行重复操作,谢谢帮助

最佳答案

可以使用按钮的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
}
}

编辑:

enter image description here

关于iphone - iPhone 中单个 UIButton 的多个操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15221874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com