弹出样式对话框 [英] pop up style dialog

查看:64
本文介绍了弹出样式对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出式按钮,该按钮以编程方式加载了5个选项,如果选择了某个选项,可以说追加文件名的末尾",那么我的更新功能需要使用一个弹出式窗口来显示一个小窗口.textField和一个保存并取消按钮出现.我不知道该怎么做.我能够得到一个不错的NSAlert示例,但是它并不需要我知道的textField.我应该使用对话类还是其他模式,还是应该尝试创建第二个笔尖?无论哪种情况,我都不知道该怎么做,所以一个好的例子或教程会很棒.

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. 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. 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.

谢谢

推荐答案

我只是四处搜寻,有人发现一种方法可以显示带有NSTextField的NSAlert,按钮并获取用户刚刚键入的文本.在Macrumors论坛上的此处略旧.

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. It's here, on the Macrumors forums, slightly old..

基本上,您可以选择:

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");
}

该代码将显示NSAlert,带有可自定义的提示,内容丰富的文本和NSTextField的默认值,并记录用户输入的内容,是否取消等信息.

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.

希望行得通!:)

这篇关于弹出样式对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆