PDA

View Full Version : Cocoa: How do I do that?




Soulstorm
Apr 28, 2008, 07:53 AM
I am building a program, and I want to do the following:

When a user presses a specific button, I want to display some names in a window containing a table view. The user must select one of these names, and he/she must press ok. Then the value selected will be returned, and I must do something with it (which is irrelevant).

What I don't know is how can I lock the rest of the user interface when displaying this panel. By the time the panel is displayed, I want force the user to make a choice! I don't want the user to be able to tackle with the rest of the user interface until he makes a choice.

How do I do that? Is there any way that can be done using something else (sheets?)?



Sayer
Apr 28, 2008, 08:27 AM
Take a piece of paper and draw out the UI you want. Make different versions of it to flesh out the ideas first.

For example have one larger window with the name-selection at the top and the rest of the UI "hidden" by shrinking the height of the window. When a selection is made expand the window to show the rest of the UI (Like System Preferences).

Or make one with a sheet blocking the UI.

Or make something else.

Make a flow diagram showing the basic steps and see if it makes sense. Then build up a UI and try it out in IB.

You'd be surprised how many "professionals" draw things out on paper first and make many different test versions of a UI before getting it just right.

robbieduncan
Apr 28, 2008, 08:34 AM
You can run any NSWindow as modal via this NSApplication method (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/NSApplication/runModalForWindow:). Once it's modal you need to have some method that will be called via a UI action that will stop the modal session. Once this is done it's up to you how you get the value back. You could set a variable in the NSWindowController sublcass that owns the modal window as an example.

Soulstorm
Apr 28, 2008, 09:40 AM
Once it's modal you need to have some method that will be called via a UI action that will stop the modal session. Once this is done it's up to you how you get the value back. You could set a variable in the NSWindowController sublcass that owns the modal window as an example.

Hm... That was the answer I was looking for.... Maybe! I will try that and I will post back with the results. Thank you both for your answers.