• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Presenting VCs as Sheets — Completion Handler?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Presenting VCs as Sheets — Completion Handler?


  • Subject: Re: Presenting VCs as Sheets — Completion Handler?
  • From: Mike Abdullah <email@hidden>
  • Date: Tue, 25 Aug 2015 18:03:48 +0200

> On 25 Aug 2015, at 03:56, Seth Willits <email@hidden> wrote:
>
> 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.

Generally a delegate rather than block seems a bit neater here, but yeah, this seems to be the general expected approach. I figure a major advantage is that whatever callback system you put in place can report back far more than just a integer value; it can also specify an object the user selected, that sort of thing.


_______________________________________________

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


References: 
 >Presenting VCs as Sheets — Completion Handler? (From: Seth Willits <email@hidden>)

  • Prev by Date: Re: Completely baffled by NSTabViewController + Autolayout (OS X bug)
  • Next by Date: Re: Auto layout in XCode 6.4
  • Previous by thread: Presenting VCs as Sheets — Completion Handler?
  • Next by thread: Auto layout in XCode 6.4
  • Index(es):
    • Date
    • Thread