Lefora Free Forum
login join
Loading
602 views

NSOpen Panel

Page 1
1–2
regular - member
54 posts

Hello all. I am opening a panel to select an image and putting the resulting path in a field. No problem. But how can I determine which button opened the panel in the first place? My code is below.

Thank you,
                   Todd

-(IBAction)findImage:(id)sender;
{
    NSOpenPanel *op = [NSOpenPanel openPanel];
    [op beginSheetForDirectory:nil
                          file:nil
                         types:[NSImage imageFileTypes]
                modalForWindow:[NSApp mainWindow]
                 modalDelegate:self
                didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
                   contextInfo:nil];
}

- (void)openPanelDidEnd:(NSOpenPanel *)op
             returnCode:(int)returnCode
            contextInfo:(void *)ci
{
    if (returnCode != NSOKButton)return;
    NSString *path = [op filename];
    [imagePathField setStringValue:path];
}

?
288 posts

Todd

I think that's what the sender is! 

I've add NSLog(@"sender = %@",sender) to one of my programs, and here's what I see.

2010-08-05 18:25:21.145 iSee[7551:a0f] sender = <NSButton: 0x10012a890>

So your findImage:(id) sender knows who pressed the button.  If you call pass that on the contextInfo: to NSOpenPanel, and you'll receive it on the delegate/call-back openPanelDidEnd.... contextInfo:

__________________
Page 1
1–2

Locked Topic


You must be a member to post in this forum

Join Now!