5

** 当在我的视图中单击一个按钮时,我想要两个文本字段和另一个按钮(删除)。如果我再次按下相同的动作最多重复 5 次。如果我点击删除按钮,两个文本字段有o删除,下面的文本字段必须出现*

-(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];

}

我怎样才能对同一个按钮进行重复操作谢谢帮助

4

3 回答 3

8

您可以使用按钮的标签属性;所以在你的 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
    }
}

编辑:

在此处输入图像描述

于 2013-03-05T10:52:34.793 回答
0

只需通过标签即可。您将节省大量内存并且可以正常工作。

于 2013-03-05T10:58:38.580 回答
0

或者你可以使用这种方法..

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

&以后使用

- (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

这将解决您的问题。我希望。

于 2013-12-28T10:34:10.423 回答