2010-05-12 63 views
0

我在當前項目中使用兩個UIAction工作表。我可以得到一個完美的工作,但是當我插入第二個操作表時,它將運行與第一個相同的參數。我如何分開定義動作表?從UIActionSheets創建操作幫助

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

回答

0

製作actionSheets實例變量並在委託方法中測試返回的操作表。

或者,編寫自己的子類UIActionSheet(和UIAlert,它也會受到同樣的煩惱),以便在捕獲返回時將回調發送到委託對象。

3

UIActionSheetUIView的子視圖,因此您可以使用tag屬性。