编程技术记录

世界你好!

NSOpenPanel控件

- (void)p_selectFileDialog:(void(^)(NSString* filePath))block
{
    NSOpenPanel* panel = [NSOpenPanel openPanel];
    [panel setCanChooseDirectories:NO];
    [panel setAllowsMultipleSelection:NO];
    [panel setMessage:@"提示语"];

    // Display the panel attached to the document's window.
    [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result){
        if (result == NSModalResponseOK)
        {
            //点击确定后的代码
            block(panel.URL.path);
        }
        else
        {
            block(nil);
        }
    }];
}

发表回复

© Beli. All Rights Reserved.