Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple actions for single UIButton in iPhone

** When a button is clicked in my view, I want two text fields and another button(remove). If I pressed again the same action to be repeated up to 5 times. and if I clicked the remove button the two text fields has o remove and below text fields has to come up*

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

}

how can i proceed for repeated action for same button thank for help

like image 894
Sivakrishna Perla Avatar asked Mar 05 '13 10:03

Sivakrishna Perla


1 Answers

You can use the tag property of button; so inside your IBAction method

- (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
    }
}

EDIT:

enter image description here

like image 115
Shekhar Gupta Avatar answered Sep 28 '22 05:09

Shekhar Gupta