Reputation: 5936
If a modal view is presented from a framework (in my case eventkit), What would be the correct way to detect if the cancel or if the done button is pressed. In my example on the didCompleteWithaction
my modal view is dismissed, an alert view is fired. I want the alert view only fired if the Done
button is pressed rather than the cancel button.
My initial thoughts were an if
statement when the the done button is pressed, however im not sure how I get the property of the done button.
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {
// Dismiss the modal view controller
[controller dismissModalViewControllerAnimated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"message" message:@"Added to calender" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
}
Upvotes: 1
Views: 710
Reputation: 4520
Look at the delegate's protocol reference: apple documentation
You will have to check the action
parameter of the delegate method, as it represents what action the user chose.
Eg
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {
// Dismiss the modal view controller
[controller dismissModalViewControllerAnimated:YES];
//this checks what action the user chose:
if (action == EKEventEditViewActionSaved) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"message" message:@"Added to calender" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
}
}
I don't know what action will be triggered by the "done" button, possibly ...ActionSaved - but check it out yourself.
Upvotes: 1
Reputation: 268293
I may be way off, but isn't action
parameter what you want?
EKEventEditViewAction
Describes the action the user took to end editing.
typedef enum {
EKEventEditViewActionCanceled,
EKEventEditViewActionSaved,
EKEventEditViewActionDeleted
} EKEventEditViewAction;
I suppose EKEventEditViewActionSaved
should correspond to Done button.
Upvotes: 1