Reputation: 306
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
Upvotes: 0
Views: 343
Reputation: 569
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!
Upvotes: 0
Reputation: 107121
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];
}
Upvotes: 1