Справка по созданию действий из справки UIActionSheets - PullRequest
0 голосов
/ 12 мая 2010

Я использую два листа 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]];
    }
}

Ответы [ 2 ]

3 голосов
/ 12 мая 2010

UIActionSheet является подпредставлением UIView, и поэтому вы можете использовать свойство tag.

0 голосов
/ 12 мая 2010

Создайте переменные экземпляра actionSheets и проверьте в методе делегата, какой лист действий был возвращен.

В качестве альтернативы, напишите свой собственный подкласс UIActionSheetUIAlert, который страдает от той же досады), чтобы отправлять обратные вызовы объекту делегата при захвате возврата.

...