Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos OSX中类似Xcode的对话框_Macos_Cocoa - Fatal编程技术网

Macos OSX中类似Xcode的对话框

Macos OSX中类似Xcode的对话框,macos,cocoa,Macos,Cocoa,我想在下面的工作表中显示带有文本输入的对话框 我尝试使用NSAlert,但我不想在对话框中显示应用程序图标 NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:kAppTitle]; [alert setInformativeText:kMsgSetDeviceName]; [alert addButtonWithTitle:kButtonOK]; [alert addButtonWithTitle:kButtonCan

我想在下面的工作表中显示带有文本输入的对话框

我尝试使用NSAlert,但我不想在对话框中显示应用程序图标

NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:kAppTitle];
[alert setInformativeText:kMsgSetDeviceName];
[alert addButtonWithTitle:kButtonOK];
[alert addButtonWithTitle:kButtonCancel];

NSString *deviceName = @"";

NSTextField *input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
[input setStringValue:deviceName];

[alert setAccessoryView:input];
[alert beginSheetModalForWindow:self.view.window completionHandler:^(NSInteger button) {

}]; 
您可以使用链接在OSX中创建自定义警报表

-(void)showCustomSheet
{
 {
 if (!_customSheet)
 //Check the myCustomSheet instance variable to make sure the custom sheet does not already exist.
 [NSBundle loadNibNamed: @"CustomSheet" owner: self];
 [NSApp beginSheet: self.customSheet
 modalForWindow: self.window
 modalDelegate: self
 didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
 contextInfo: nil];
 // Sheet is up here.
 }
}
- (IBAction)closeMyCustomSheet: (id)sender
{
 [NSApp endSheet:_customSheet];
}
- (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
 NSLog(@"%s",__func__);
 NSLog(@"return Code %d",returnCode);
 [sheet orderOut:self];
}
以下方法需要有一个不同的点来显示来自的警报

- (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet
 usingRect:(NSRect)rect
{
 NSLog(@"%s",__func__);
 if (sheet == self.customSheet)
 {
 NSLog(@"if block");
 NSRect fieldRect = [self.showAlertButton frame];
 fieldRect.size.height = 0;
 return fieldRect;
 }
 else
 {
 NSLog(@"else block");
 return rect;
 }
}

问题是什么?这不是警报窗口,是吗。您必须创建一个自定义窗口。@是。这不是窗户。我想在窗口中显示工作表。工作表就是一个窗口。该类为
NSWindow
或其子类
NSPanel
,虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,则仅链接的答案可能无效。