How can I get 1 IBAction to do another IBAction?

Discussion in 'iOS Development' started by bamhm182, Jun 8, 2009.

  1. bamhm182

    bamhm182 Member

    Joined:
    Mar 2, 2009
    Messages:
    544
    Likes Received:
    0
    Device:
    3G iPod touch
    I've searched and found nothing, I'm not sure if that's because nothing about it has been asked yet, or if I'm just not searching for the right terms.

    So, I've been toying around with it, and I got it functional, but it looks like crap, and I'm sure there's a better way to do it.

    This is what I have:

    Code:
    - (IBAction)actionOne:(id)sender;
    {
        [actionOne's actions];
    }
    
    -(IBAction)actionTwo:(id)sender;
    {
        [actionTwo's actions];
    
        [actionOne's actions];
    }
    What can I put in the second action so that it refers to -(IBAction)actionOne, rather than just reiterating what actionOne does?
  2. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    [self actionOne];?
  3. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Indeed.

    If I'm correct, IBAction is only used to link it to the Interface Builder, but it's just a method with a return type void.
  4. bamhm182

    bamhm182 Member

    Joined:
    Mar 2, 2009
    Messages:
    544
    Likes Received:
    0
    Device:
    3G iPod touch
    Sweet, that is exactly what I needed. Thanks.

    Please Register or Log in to view images



    My app is just about ready. It probably won't be of any use to anyone here, but I'll post in the apps section when it is up on the app store.
  5. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    For future ref, please remember that IBAction is just void.
  6. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    Also, if you wanted buttonTwo to do the actionOne actions after actionTwo's actions, put the following under - (IBAction)actionOne: (id) sender;

    Code:
    [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:self selector:@selector(actionOne) userInfo:nil repeats:BOOL];
  7. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    it would be better to have actionTwo do actionOne, rather than relying on a timer, as it could be slower than you expect on some devices.
  8. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    I agree, the timer is not a good idea, it will only delay the actionTwo actions.

    If you just put actionTwo's actions and then [self actionOne];, it will do actionOne's actions after actionTwo's, no need for a timer.

Share This Page