gpt4 book ai didi

macos - 像 OS X 中的 Xcode 一样的对话框

转载 作者:行者123 更新时间:2023-12-03 17:10:13 24 4
gpt4 key购买 nike

我想显示带有文本输入的对话框,如下表所示。

enter image description here

我尝试使用 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) {

}];

最佳答案

您可以使用http://www.knowstack.com/nsalert-cocoa-objective-c/在 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;
}
}

关于macos - 像 OS X 中的 Xcode 一样的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35266304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com