How to send a command between views?

Discussion in 'iOS Programming' started by tombuarts, Jul 27, 2010.

  1. tombuarts macrumors newbie

    Jan 30, 2010
    I have an app that has a view (lets call it BlueView) that has various buttons on it that when pressed load a modal view that lets you select a date (lets call this view DatePick). I figured out how to pass the date back to the BlueView. The date that was picked will be used in a sub that exists in BlueView called calculate. What I need to figure out now is how do I call the calculate sub from the DatePick view as it is being dismissed? I don't know if i explained this good enough, and I've researched this as best I can. I simply don't know what the command/code that would invoke this is called. I am fairly new to this, but I have been able to work through numerous obstacles so far in my app design. I'm not looking for someone to post code that I can cut and paste, I just need to be lead in the right direction. Any help would be greatly appreciated. Thanks.
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    First, by "sub" do you mean "method"? Using the proper terminology will help the rest of us to better understand what you're asking.
  3. LastLine macrumors 65816

    Aug 24, 2005
    Yeah he means a method, bit of VB terminology there if I'm not mistaken.
  4. themoonisdown09 macrumors 601


    Nov 19, 2007
    Georgia, USA
  5. ranguvar macrumors 6502

    Sep 18, 2009
    It actually depends on the sub. For instance, chicken breast with Southwestern dressing crashes any app, I am told.
  6. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    If it's an app wide command, and not unique to a particular pair of objects, sending a Notification from the caller, and registering a notification handler in the callee would also work.
  7. tombuarts thread starter macrumors newbie

    Jan 30, 2010
    Ok, I've been trying to figure this out and I am missing something. I set up the Protocol in BlueViewController.h like so;

    @protocol dateset
    [self performSelector:mad:selector(calculate)];

    I added #include "BlueViewController.h" to DatePickController.m and in the selectButtonPressed method I put

    @protocol (dateset);

    The date definitely gets passed to the BlueView when I press the Select button, but I can't call the calculate method in BlueViewController.m. I know something with the syntax for the protocol is incorrect, but I can't figure out what. I probably didn't describe this perfectly, but by the other posts I hope you can figure out what I am doing. Thanks for helping a newbie.
  8. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    This sounds like a problem which can be solved by delegation.

    Add a delegate instance variable to your DatePick. Have your blueView assign itself as the delegate for your DatePick. Have DatePick check for the existence of a delegate, and, if so, call the delegate method when it is being dismissed (or whatever).

Share This Page