Presenting VCs as Sheets — Completion Handler?
Presenting VCs as Sheets — Completion Handler?
- Subject: Presenting VCs as Sheets — Completion Handler?
- From: Seth Willits <email@hidden>
- Date: Mon, 24 Aug 2015 18:56:38 -0700
Naturally we're all accustomed to the pattern:
[sheet beginSheetModalForWindow:window completionHandler:^(NSInteger response){
...
}];
But with the new "presentation" API, there's no built-in mechanism for handling the sheet being closed. To have a similar pattern as before would require:
otherVC.completionHandler = ^(NSInteger response){
...
};
[someVC presentViewControllerAsSheet:otherVC];
@implementation OtherViewController
// @property void (^completionHandler)(NSInteger response);
- (IBAction)ok:(id)sender
{
[self dismissController:nil];
if (self.completionHandler) {
self.completionHandler(NSOKButton);
self.completionHandler = nil; // Gotta kill the likely circular reference.
}
}
....
@end
No doubt it's flexible, but it's a bit verbose. I just want to double-check I didn't miss some other pattern we're supposed to be using.
--
Seth Willits
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden