簡體   English   中英

UIAlertView按鈕操作

[英]UIAlertView Button Action

如何在UIButton點擊中使用兩個動作?我有一個UIAlertView顯示兩個按鈕。再次播放並退出。現在我想在這些按鈕的點擊事件中執行兩個方法。

更新 - 2016年5月

UIAlertView已棄用。 您現在可以使用UIAlertController作為解釋在這里

UIAlertView的舊答案

  1. 你可以像這樣創建一個UIAlertView

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Really reset?" message:@"Do you really want to reset this game?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"reset", nil]; [alert show]; 
  2. 要處理AlertView按鈕單擊,您必須符合 UIAlertViewDelegate協議。

     @interface YourViewController:UIViewController<UIAlertViewDelegate>{ ....... ....... } 
  3. 然后實現 UIAlertViewDelegate協議方法,

     - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == [alertView cancelButtonIndex]){ //cancel clicked ...do your action }else{ //reset clicked } } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM