Having 2 UIActionSheets In An App?

Discussion in 'iOS Development' started by Nickll9009, Sep 20, 2008.

  1. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    I am trying to create an app with two UIActionSheets. The problem is that it uses the buttonIndex's from the first sheet for the second one.

    Code:
    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(int)buttonIndex
    { 
        if(buttonIndex == 0)
            {
               //action//
            }
        else if(buttonIndex == 1)
            {
                          //action//
            }
        else if(actionSheet == sheetTwo)
            {
        if(buttonIndex == 0)
            {
                          //action//
            }
        else if(buttonIndex == 1)
            {
                          //action//
            }
        else if(buttonIndex == 2)
            {
                          //action//
            }
        else if(buttonIndex == 3)
            { 
                          //action//
            }
        
        
      }
    }
    I have searched, and come up with nothing. Any ideas?
  2. ipodtouchmaster05

    ipodtouchmaster05 Well-Known Member

    Joined:
    Sep 30, 2007
    Messages:
    1,787
    Likes Received:
    41
    Device:
    iPhone 5 (Black)
    Code:
    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(int)buttonIndex
    { 
        if(sheet == sheet1)
            {
        if(button == 1)
            {
                          //action//
            }
    }
        if(sheet == sheetTwo)
            {
        if(button == 0)
            {
                          //action//
            }
        else if(button == 1)
            {
                          //action//
            }  
      }
    }
    try that
  3. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    Nope, Same Problem.
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    You have to check which sheet is being called and act accordingly. There's a reason the function feeds you the variable.

    Please, read up, it's not rocket science.

    If(sheet == yourSheet)react accordingly; else if(sheet == yourOtherSheet)react accordingly;
  5. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    You mean like this?

    Code:
    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(int)buttonIndex
    {
    if(actionSheet == sheetOne)
    { 
        if(buttonIndex == 0)
            {
               //action//
            }
        else if(buttonIndex == 1)
            {
                          //action//
            }
        else if(actionSheet == sheetTwo)
            {
        if(buttonIndex == 0)
            {
                          //action//
            }
        else if(buttonIndex == 1)
            {
                          //action//
            }
        else if(buttonIndex == 2)
            {
                          //action//
            }
        else if(buttonIndex == 3)
            { 
                          //action//
            }
        
        
      }
    }
    When I do that no buttons on any sheet work.
  6. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    Code:
    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(int)buttonIndex
    {
    if(actionSheet == sheetOne)
    { 
        if(buttonIndex == 0)
            {
               //action//
            }
        else if(buttonIndex == 1)
            {
                          //action//
            }
    }
        if(actionSheet == sheetTwo)
            {
        if(buttonIndex == 0)
            {
                          //action//
            }
        else if(buttonIndex == 1)
            {
                          //action//
            }
        else if(buttonIndex == 2)
            {
                          //action//
            }
        else if(buttonIndex == 3)
            { 
                          //action//
            }
        
        
      }
    }
    try this
  7. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    my god, this is freaking easy guys.

    Code:
    if(actionSheet == yourSheet) {
            // Handle events from yourSheet
            } else {
            // Handle events from another sheet
    }

Share This Page