0

I have a view with three buttons on it.

when any of them are pressed it calls a custom UIView with another button on it.

what i would like to do is change the custom views button to different actions, depending on what button called the new view.

hopefully this makes sense.

thanks

2 Answers 2

1

I'll suggest you to dynamically create button for the custom view:

CGRect buttonFrame = CGRectMake( 10, 280, 100, 30 );
UIButton *button = [[UIButton alloc] initWithFrame: buttonFrame];
[button setTitle: @"My Button" forState: UIControlStateNormal];
[self.view addSubview: button];
if(//clicked button 1)
 {
     [button addTarget: self 
           action: @selector(action1:) 
 forControlEvents: UIControlEventTouchDown];
 }
 else if(//clicked button 2)
 {
     [button addTarget: self 
           action: @selector(action2:) 
 forControlEvents: UIControlEventTouchDown];
 }
else
 {
     [button addTarget: self 
           action: @selector(action3:) 
 forControlEvents: UIControlEventTouchDown];
 }
2
  • this seems to be on the right lines, thanks for your help, but how would i know what button called the custom view?
    – Spriggsy
    Nov 2, 2012 at 17:59
  • put an integer in the custom view class, when you calls the custom view set the integer value to 1 or 2 or 3 according to the clicked button
    – Midhun MP
    Nov 2, 2012 at 18:01
0

I believe you can do something like this to dynamically add actions to buttons:

UIButton *button = [UIButton alloc] init]
[button addTarget:self action: @selector(pressButton:) forControlEvents:UIControlEventTouchUpInside];

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.