2011-10-31 65 views
1

我已經創建了UIActionsheet,但我無法弄清楚如何將其鏈接到現有的IBAction。將UIActionSheet按鈕與當前的IBAction鏈接

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (buttonIndex == 0) { 
    self.label.text = @"Destructive Button Clicked"; 
      }} 

這是我的代碼,我點擊一個按鈕,我希望它鏈接到我已經得到的以下IBAction。

- (IBAction)doButton; 

那麼,我將如何去鏈接呢?任何幫助將不勝感激。 感謝

+0

如果我回答你的問題,請您務必在 「接受我的答案。」 – James

回答

1
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex { 
if (buttonIndex == 0) { 
self.label.text = @"Destructive Button Clicked"; 
[self doButton]; 
} 

}

0

來做到這一點是一個UIActionSheetDelegate添加到您的類並調用動作片,你IBAction爲最好的辦法。

.h文件中

@interface ViewController : UIViewController <UIActionSheetDelegate> 

-(IBAction)doButton; 

@end 

.m文件

-(IBAction)doButton { 

UIActionSheet *doSheet = [[UIActionSheet alloc] initWithTitle:@"Your title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Button 0", @"Button 1", nil]; 

[doSheet showInView:self.view]; 
} 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex { 
     if (buttonIndex == 0) { 
      //Do Something 
     } 
     if(buttonIndex == 1) { 
      //Do Something else 
     } 
} 
+0

他的問題中已包含此代碼。 – James