Beginner NSAlert question

  • on 11/6/07 10:29 AM, <paul_bruneau...> purportedly said:

    > In the middle of this -complete code, an alert might be required. Do
    > I put the alert code in the orderStep class, or in the controller
    > class?

    This may be a gray area of MVC, but I don't see a problem assuming that the
    NSAlert class is the controller class in this situation, and the model is
    simply asking the controller to prompt for information.

    > And is it common for people to use a single didEndSelector for
    > several alerts?

    Yes, or at least, it is not uncommon. That's one of the reasons for
    contextInfo.

    > In my pre-Cocoa life, it was my nature to put something like an alert
    > asking a simple yes or no question inline in the code that needs the
    > answer so having to decide where to put this code is a puzzle for me.
    > I'd rather not have a separate didEndSelector at all.

    didEndSelector  does not have to do with where your code is, it has to do
    with the nature of modal sheets. Because the sheet starts an event loop, you
    need a callback method to return control to the caller. This is likely the
    main issue you are looking at, if you are confronted with the need to put up
    a sheet in the middle of a method.

    You can use a modal alert window instead of a sheet, which does what you may
    want, but watch out for HIG (Human Interface Guidelines). Otherwise you may
    have to segment the method call, regardless of "where" you put the method.

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
  • Hi-

    I'm trying to understand the right way to use an NSAlert regarding
    where it should be handled (MVC) and how many didEndSelector methods
    I should have.

    I have a window where a button allows me to perform a task (called -
    complete) on the currently-selected orderStep object that appears in
    a custom view. To perform the task, my view controller (which, right
    or wrong handles controller tasks for the view and the window) sends
    a message to the orderStep object, in whose class appears the -
    complete code.

    In the middle of this -complete code, an alert might be required. Do
    I put the alert code in the orderStep class, or in the controller
    class? The task definitely "belongs" to that object so my feeling is
    that the alert is part of that and belongs there. But putting alert
    code in my model seems wrong.

    But as wrong as it seems, it also seems wrong to tie this task into
    my controller object since this task might need to be performed from
    any number of other places in my application that have nothing to do
    with the view or its controller.

    And is it common for people to use a single didEndSelector for
    several alerts? or should I always make a new method for each alert
    every time?

    In my pre-Cocoa life, it was my nature to put something like an alert
    asking a simple yes or no question inline in the code that needs the
    answer so having to decide where to put this code is a puzzle for me.
    I'd rather not have a separate didEndSelector at all.

    Thanks for any insights
  • On Nov 6, 2007, at 11:25 AM, Keary Suska wrote:

    > didEndSelector  does not have to do with where your code is, it has
    > to do
    > with the nature of modal sheets. Because the sheet starts an event
    > loop, you
    > need a callback method to return control to the caller. This is
    > likely the
    > main issue you are looking at, if you are confronted with the need
    > to put up
    > a sheet in the middle of a method.
    >
    > You can use a modal alert window instead of a sheet, which does
    > what you may
    > want, but watch out for HIG (Human Interface Guidelines). Otherwise
    > you may
    > have to segment the method call, regardless of "where" you put the
    > method.

    Thank you Keary-

    I understand now why the separate method is required. I will do it
    the right way and segment my methods where necessary to use the
    NSAlert sheets. Thanks for the answers to my other questions too.
  • On 6-Nov-07, at 9:25 AM, Keary Suska wrote:

    > on 11/6/07 10:29 AM, <paul_bruneau...> purportedly said:
    >
    >> In the middle of this -complete code, an alert might be required. Do
    >> I put the alert code in the orderStep class, or in the controller
    >> class?
    >
    > This may be a gray area of MVC, but I don't see a problem assuming
    > that the
    > NSAlert class is the controller class in this situation, and the
    > model is
    > simply asking the controller to prompt for information.

    In my opinion, a model object should have no knowledge of any
    associated controller(s).  Any information required by a model's
    manipulation methods should be either supplied as arguments, available
    through a delegate, or implicit in the model itself.  It is the
    controller's responsibility to prompt for such information where
    necessary.  The only communication from model to controller should
    occur through key/value observation.  This discipline is particularly
    useful when providing multiple views of a model.

    I would regard a situation where a model method does not have
    sufficient information as exceptional; the controller which invoked
    the method can present an alert sheet in response to caught exceptions.

    Cheers,
    dave
  • Am 06.11.2007 um 17:25 schrieb Keary Suska:
    > because the sheet starts an event loop, you need a callback method
    > to return control to the caller.

      Err... I think you swapped some words there:

      A *modal panel* starts its own nested event loop, and handles events
    in its one window until someone clicks OK or cancel. This effectively
    blocks the whole application (at least from the user's point of view).

      A sheet *doesn't* start an event loop. If you create a sheet, it is
    simply a window that you created. All its events are handled on the
    main event loop like for other windows. All it does is block (most)
    events coming to the window on which you show the sheet. So, a user
    can not use the window on which the sheet is, but all other windows in
    the application.

      Since creating a sheet returns immediately, and doesn't block the
    app, you need another way to detect when the sheet's buttons have been
    clicked. This is what the didEndSelector: on the default sheets is for.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • On Nov 6, 2007, at 4:50 PM, David Spooner wrote:

    > On 6-Nov-07, at 9:25 AM, Keary Suska wrote:
    >
    >> on 11/6/07 10:29 AM, <paul_bruneau...> purportedly said:
    >>
    >>> In the middle of this -complete code, an alert might be required. Do
    >>> I put the alert code in the orderStep class, or in the controller
    >>> class?
    >>
    >> This may be a gray area of MVC, but I don't see a problem assuming
    >> that the
    >> NSAlert class is the controller class in this situation, and the
    >> model is
    >> simply asking the controller to prompt for information.
    >
    > In my opinion, a model object should have no knowledge of any
    > associated controller(s).  Any information required by a model's
    > manipulation methods should be either supplied as arguments,
    > available through a delegate, or implicit in the model itself.  It
    > is the controller's responsibility to prompt for such information
    > where necessary.  The only communication from model to controller
    > should occur through key/value observation.  This discipline is
    > particularly useful when providing multiple views of a model.
    >
    > I would regard a situation where a model method does not have
    > sufficient information as exceptional; the controller which invoked
    > the method can present an alert sheet in response to caught
    > exceptions.

    This is probably my biggest struggle in cocoa programming.
    Controllery things keep sneaking into my models. I will keep your
    message around to beat against my head until I internalize it. Thank
    you.
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today