[英]pop up style dialog
I have a pop up button that is loaded with 5 options programicically, if a particular option is selected, lets say, "append the end of file name",then my update function needs to cause a small pop up window with a textField and a save and cancel button to appear. 我有一个弹出式按钮,该按钮以编程方式加载了5个选项,如果选中了某个特定选项,可以说“追加文件名的末尾”,那么我的更新功能需要使用文本字段和一个保存并取消按钮出现。 I don't know how to do this. 我不知道该怎么做。 I was able to get a nice NSAlert example to work but it does not take a textField that I know of. 我能够得到一个不错的NSAlert示例,但是它并不需要我知道的textField。 Is there a dialog class or some other modal I should be using or should I be trying to create a second nib? 我应该使用对话类还是其他模式,还是应该尝试创建第二个笔尖? in either case I don't really know how to do it so a good example or tutorial would be great. 无论哪种情况,我都不知道该怎么做,所以一个好的例子或教程会很棒。
Thanks 谢谢
I just searched around, and there is a method someone found to display an NSAlert with an NSTextField, buttons and get the text the user has just typed. 我只是四处搜索,有人发现一种方法来显示带有NSTextField的NSAlert,按钮并获取用户刚刚键入的文本。 It's here, on the Macrumors forums, slightly old.. 在这里,在Macrumors论坛上,稍旧。
Essentially you could just go with: 本质上,您可以使用:
NSString *prompt = @"Please enter text to append to file name:";
NSString *infoText = @"What happens here is...";
NSString *defaultValue = @"Default Value";
NSAlert *alert = [NSAlert alertWithMessageText: prompt
defaultButton:@"Save"
alternateButton:@"Cancel"
otherButton:nil
informativeTextWithFormat:infoText];
NSTextField *input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)];
[input setStringValue:defaultValue];
[alert setAccessoryView:input];
NSInteger button = [alert runModal];
if (button == NSAlertDefaultReturn) {
[input validateEditing];
NSLog(@"User entered: %@", [input stringValue]);
} else if (button == NSAlertAlternateReturn) {
NSLog(@"User cancelled");
} else {
NSLog(@"bla");
}
That code would display the NSAlert, with customisable prompt, informative text and default value for the NSTextField, plus log what the user entered, whether they cancelled, etc. 该代码将显示NSAlert,带有可自定义的提示,内容丰富的文本和NSTextField的默认值,并记录用户输入的内容,是否取消等信息。
Hope that works! 希望有效! :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.