我对 Xcode 和 Cocoa/Objective-C 相当陌生,我正在尝试实现像 QInputDialog 这样简单的东西,可以在整个程序中重复使用 - 每次启动和返回时都会向用户发送一条独特的消息结果是一个字符串。
我在网上搜索并找到了多种方法,但似乎没有什么是非常清晰或简洁的 - 无论如何都足以让我理解。
有没有像这样简单的事情:
- 从带有新消息标签的方法以字符串形式向用户创建/启动一个窗口。
- 有一个 NSTextField 来接收用户输入。
- 关闭窗口并将文本字段中的字符串(如果接受)返回到调用方法。
??
I'm fairly new to Xcode and Cocoa/Objective-C and I'm trying to implement something as simple as a QInputDialog that can be re-used throughout the program - with a unique message to the user each time it is launched and return a string as a result.
I have searched the web and found multiple methods but nothing seems to be quite clear or concise - well enough for me to understand anyway.
Is there anything out there as simple as:
- Create/Launch a window from a method with a new message label to the user in the form of a string.
- Has an NSTextField to receive the users input.
- Close the window and return the string from the text field (if accepted) to the calling method.
??
发布评论
评论(1)
输入的模态提示与 Mac 非常不同。这就像用板球棒砸碎用户的脸并大喊“现在告诉我答案!”
正确的解决方案是将文本字段放入非模态窗口中,以便当用户调用需要该值的任何操作时该值已经准备好。发出蜂鸣声并显示 “嘿,你忘了这个”图标(如果用户尚未填写该字段并且您需要在那里输入一个值)。如果该字段与用户启动操作的窗口不相关,或者如果您需要多个事实作为输入,则以非模态方式显示另一个窗口,并带有自己的窗口控制器,以接收所有输入你需要采取行动。
单独的非模式窗口还将使用户能够并行填写和/或执行多个此类操作。
如果您必须使用模式对话框要求该值,您可以并且应该 将其设为工作表,但您仍然需要构建面板并IB 或代码中的内容从头开始。
另请参阅Sheet 编程指南和 //developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AppleHIGuidelines/" rel="nofollow">人机界面指南。
Modal prompts for input are very un-Mac-like. It's like smashing the user's face in with a cricket bat and yelling “TELL ME THE ANSWER NOW!”
The correct solution is to put your text field into a non-modal window, so that the value is already ready when the user invokes whatever action needs the value. Beep and show the “hey, you forgot this” icon if the user hasn't filled in the field and you need a value there. If the field is not relevant in the window the user starts the action from, or if you're going to need several facts as input, then show another window, non-modally, with its own window controller, to take in all the input you'll need for the action.
A separate, non-modal window will also enable the user to fill out and/or perform multiple such actions in parallel.
If you must demand the value with a modal dialog, you can and should make it a sheet, but you'll still need to build the panel and its contents from scratch in IB or code.
See also the Sheet Programming Guide and the chapter on windows in the Human Interface Guidelines.