您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

iPhone 開發:UIAlertView 的確定與取消按鈕處理

編輯:iOS 開發綜合

建立提示框

UIAlertView 可用來顯示提示訊息與按鈕。建立時可指定標題、內容、代理與按鈕文字。

UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"b"
    message:@"s"
    delegate:self
    cancelButtonTitle:@"確定"
    otherButtonTitles:@"取消", nil];
[a show];

處理按鈕事件

按下按鈕後,會呼叫 UIAlertViewDelegate 的 clickedButtonAtIndex 方法。buttonIndex 用來判斷使用者按下哪個按鈕。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"%i", buttonIndex);
}

若要在不同按鈕執行不同行為,可根據 buttonIndex 分支處理。新建的 iOS 專案也可改用 UIAlertController,但舊有程式仍常看到這種寫法。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved