Instance Method

show(relativeTo:of:preferredEdge:)

Shows the picker, populated with sharing services related to the instance items.

Declaration

func show(relativeTo rect: NSRect, of view: NSView, preferredEdge: NSRectEdge)

Parameters

rect

The rectangle the picker should be showed relative to. The coordinates are in the view coordinate system. Passing NSZeroRect causes the view bounds to be used.

view

The view.

preferredEdge

The preferred edge of the view to display the picker. See NSRectEdge for the possible values.

Discussion

When the user selects one of the sharing services, the sharing service will be performed. This method must be called on mouse down by configuring the button used to trigger showing the picker to send its action on mouse down. You would typically do this by adding the following code to an appropriate awakeFromNib method:

- (void)awakeFromNib {
    NSButton *shareButton = self.mySharePickerButton; // your outlet to the button
    [shareButton sendActionOn:NSLeftMouseDownMask];
}

Here is an example implementation of the action method your share button would call:

- (IBAction)share:(id)sender
{
    NSArray * items = @[];
    NSSharingServicePicker * picker = [[NSSharingServicePicker alloc] initWithItems:items];
    picker.delegate = self;
    [picker showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
}