views:

174

answers:

2

I am using two UIAction sheets within my current project. I can get one to work perfectly fine but when i insert a second action sheet it runs the same arguements as the first. How do i define the actionsheets seperatly?

-(IBAction) phoneButtonClicked:(id)sender
{
    // open a dialog with just an OK button
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                        delegate:self cancelButtonTitle:@"Cancel" 
                                                        destructiveButtonTitle:nil 
                                                        otherButtonTitles:[NSString stringWithFormat:@"Phone: %@",phone],nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
    [actionSheet release];  
}

-(IBAction) mapButtonClicked:(id)sender
{
    // open a dialog with just an OK button
    UIActionSheet *mapActionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                        delegate:self cancelButtonTitle:@"Cancel" 
                                                        destructiveButtonTitle:nil 
                                                        otherButtonTitles:[NSString stringWithFormat:@"Map"],nil];
    mapActionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [mapActionSheet showInView:self.view];  // show from our table view (pops up in the middle of the table)
    [mapActionSheet release];   
}


-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
        if(buttonIndex == 0){
            NSString *callPhone = [NSString stringWithFormat:@"tel:%@",phone];
            NSLog(@"Calling: %@", callPhone);
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    }
}
A: 

Make the actionSheets instance variables and test in the delegate method which action sheet was returned.

Alternatively, write your own subclass of UIActionSheet (and UIAlert, which suffers from the same annoyance), to send callbacks to a delegate object when the return is captured.

Paul Lynch
+1  A: 

UIActionSheet is a subview of UIView and therefore you could use the tag property.

bddckr