开发者

QInputDialog like thing in Cocoa/Xcode?

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 th开发者_运维知识库roughout 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.

??


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜