Question

I need to open image using NSOpenPanel. I did it using the following code:

NSOpenPanel *open = [NSOpenPanel openPanel];
NSArray *fileTypes = [[NSArray alloc] initWithObjects:@"jpg", @"gif", @"png", nil];
NSURL *filePath = [[NSURL alloc] init];

[open setCanChooseFiles:YES];
[open setAllowedFileTypes:fileTypes];
[open setAllowsMultipleSelection:NO];

if ([open runModal] == NSOKButton) {
    filePath = [open URL];
    NSLog(@"%@", [filePath path]);
}

NSImage *selectedImage = [[NSImage alloc] initWithData:[NSData dataWithContentsOfFile:[filePath path]]];
[imageView setImage:selectedImage];

When I run my app, there's opening file dialog, i select my jpg image, and there's nothing. I don't see my image in image view as expected. Help me please.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top