Re: Getting a return value from a dialog
Re: Getting a return value from a dialog
- Subject: Re: Getting a return value from a dialog
- From: email@hidden (Kris Rambish)
- Date: Thu, 29 Jun 2006 03:39:43 +0000
I agree with Andre, but if that isn't clear here is my stab at it:
It sounds like all you want to do it pop out a sheet that has a NSTextField with a NSButton. All I would do is create a new panel in Interface Builder, and add the NSTextField and a NSButton. Then I would wire your window controller to the NSTextField and wire the button to the controller as an action.
Then when the player gets the high score I would call something like:
[NSApp beginSheet: <your panel member variable>
modalForWindow: <your window member variable>
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
[NSApp runModalForWindow: <your window member variable>];
[NSApp endSheet: <your panel member variable>];
Then when the user clicks ok, you can close the panel and get the name from the NSTextField.
Kris
-------------- Original message ----------------------
From: email@hidden
> Your controller should be the one to slide out a sheet/window and
> display it to the user.
> In Interface Builder, wire-up/bind (preferably bindings) all the
> connections before hand to your (dialog) window that will gather info
> from the user.
>
> When appropriate, the controller grabs the window, displays the sheet/
> window, and a button on the sheet, when clicked, can tell the
> controller (via action/target) to dismiss the sheet/window.
> IOW, its not a "built in functionality" to get a return from a
> window, instead you set up the window before hand just as if it were
> a normal window that always shows up (except this one doesn't display
> automatically), then your controller "orders" it to front, or as a
> sheet to slide out.
>
> So, just to clarify, you just set up a normal window, you don't need
> to get a return value unless your want a cancel/o.k button (which you
> can get with a sheet display method).
> Then you just order it to front from your controller or use a sheet
> display method. The controls (text fields, menus etc) are wired up to
> the controller just like normal.
> You just then hide and display that window when appropriate.
>
> (Try to think in a Model/View/Controller way and its easier)
>
> Hope this helps.
>
> Andre
>
> Dan Cavanagh wrote:
>
> > Hello all,
> >
> > I am very much an amateur programmer, but have been learning Obj-C
> > for a while now, and am to the point where I am struggling more
> > with concepts rather than the language. (That's a good thing). I
> > have learned much from this list, and I thank the regular
> > contributers for my better understanding.
> >
> > I have run into a conceptual roadblock: I am looking for a way to
> > pop a dialog and get a return value. My first fully-functioning app
> > is a tetris clone, so when someone gets a high score, I ask for
> > their name in a dialog (sheet, modal window, doesn't matter to me).
> > I have poured through Apples docs, searched mailing lists, and
> > Googled a lot, but the most I could come up with is the following
> > post:
> >
> > http://www.omnigroup.com/mailman/archive/macosx-dev/2002-October/
> > 042490.html
> >
> > The reply says that there is no built-in function/method/class to
> > do that. So, my question to everyone is, what is the best way to
> > get a user-inputted value from a dialog? Several solutions come to
> > mind: global variable (doesn't really seem appropriate) and
> > notification (lots of overhead, I would think). I guess I'm looking
> > to implement something similar to a dialog "function/method" that
> > gives a return value.
> >
> > Any help is greatly appreciated. A shove in the right direction
> > would do me well. Thanks!
> >
> > Dan Cavanagh
> > _______________________________________________
> > MacOSX-dev mailing list
> > email@hidden
> > http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden