0

我在当前项目中使用了两个 UIAction 表。我可以让一个工作完美无缺,但是当我插入第二个操作表时,它会运行与第一个相同的论点。我如何单独定义操作表?

-(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]];
    }
}
4

2 回答 2

3

UIActionSheet是的子视图,UIView因此您可以使用该tag属性。

于 2010-05-12T11:34:37.677 回答
0

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.

于 2010-05-12T11:20:22.820 回答