1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How to send a command between views?

Discussion in 'iPhone/iPad Programming' started by tombuarts, Jul 27, 2010.

  1. macrumors newbie

    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. Moderator


    Staff Member

    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. macrumors 65816

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


  5. macrumors 6502

    It actually depends on the sub. For instance, chicken breast with Southwestern dressing crashes any app, I am told.
  6. macrumors 603

    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. macrumors newbie

    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. macrumors 603

    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