Problems with Cancel Button and UIActionSheet

前端 未结 3 1024
星月不相逢
星月不相逢 2021-02-19 20:13

How do I determine if the cancel button was pressed on a UIActionSheet?

My UIActionSheet is set up like this:

-(IBAction)fileButtonPressed
{
    UIAction         


        
3条回答
  •  别那么骄傲
    2021-02-19 20:40

    The trick turns out to be not to use the automatic cancel button but to add it yourself.

    The other slight gotcha is to add the cancel button at the end and not at the beginning.

    -(IBAction)fileButtonPressed
    {
        UIActionSheet *mymenu = [[UIActionSheet alloc] 
                                 initWithTitle:@"Select Folder" 
                                 delegate:self 
                                 cancelButtonTitle:nil 
                                 destructiveButtonTitle:nil 
                                 otherButtonTitles:nil];
        for (int nb=0; nb<3; nb++) 
        { 
            [mymenu addButtonWithTitle:@"Button Name"]; 
        }
    
        mymenu.cancelButtonIndex = [mymenu addButtonWithTitle: @"Cancel"];
    
        [mymenu showInView:self.view];
    }
    

    credit to this stackoverflow entry for the answer.

提交回复
热议问题