Hi everyone,
I am designing an application which will be using pop-Up windows extensively, so I have decided to write a piece of code to programmatically set it up.
The idea is that every pop-Up will be effectively the same – it will have message, asking if the user really wants to do something and two buttons – yes and no. Standard alert pop-Ups are of no use as I want to customize the appearance.
The only difference in the pop-Ups is what happens when button "Yes" is pressed. I therefore wish to be able to place the code of creation of pop_up window in the application delegate file and then, when running that code, return the instance of the Yes button. I then wish to be able to add a selector to it from whichever part of program to do the desired action.
However, once I add a selector from the class that calls for delegate to display the pop-Up I get the warning: unrecognized selector sent to instance....
Th obvious solution is to duplicate the pop-up creation code in every class that might want to use it, but I would like to make a more flexible design.
Basically, can I add a selector from the class other then the one which created the button?
here is what I have in my appDelegate:
UIButton *yesButton = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:trialView.frame];
Code:
-(UIButton *)showPopUp:(NSString *)messageText and:(UIView *)view and:(NSString *)imageName and:
(NSString *)noButtonName and :(NSString *)noButtonNameHighlighted and:
(NSString *)yesButtonName and :(NSString *)yesButtonNameHighlighted {
THERE IS ALSO SOME CODE HERE WHIC IS IRRELEVANT
UIButton *yesButton = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:trialView.frame];
[yesButton setImage:[UIImage imageNamed:yesButtonName] forState:UIControlStateNormal];
[yesButton setImage:[UIImage imageNamed:yesButtonNameHighlighted] forState:UIControlStateHighlighted];
[yesButton addTarget:self action:@selector(hideSemiTransparentView:) forControlEvents:UIControlEventTouchUpInside];
yesButton.center = CGPointMake(0, 0);
[mainPopUpView addSubview:yesButton];
return yesButton;
}
This is the part of code, as the whole function is huge and the rest of the code is only displaying and works very well. The method hideSemiTransparentView: is declared in the appDelegate.
Now I want to be able to call this pop-up creation method and add a method to the action from another class like this:
Code:
einstein2AppDelegate *delegate = (einstein2AppDelegate *)[[UIApplication sharedApplication] delegate];
UIButton *button = [delegate showPopUp:@"aaaaaaa!!" and:self.view and:@"Background.png" and:@"yes_noiPhone.png" and:
@"yes_noiPhoneHighlighted.png" and:@"yes_noiPhone.png" and:@"yes_noiPhoneHighlighted.png"];
[button addTarget:button action:@selector(reset2) forControlEvents:UIControlEventTouchUpInside];
Does not work when I press on the button

Any ideas?