---
title: "UIAlertView的基本操作"
author: "helmsman_xcode"
date: "2011-08-15T17:59:04Z"
tags: []
categories: ["移动开发"]
slug: "uialertview"
draft: false
lastmod: "2011-08-15T17:59:04Z"
id: 1149794
url: "https://helmsman-xcode.iteye.com/blog/1149794"
---

UIAlertView 提示框

 

定义并显示：

 

```
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"title" message:nil delegate:nil
 cancelButtonTitle:@"button" otherButtonTitles: @"otherButton",nil];
[alert show];
[alert release];
```

 

多个按钮可对otherButtonTitles进行设置 例如：otherButtonTitles: @"otherButtonOne",@"otherButtonTwo"，nil

 

当多个按钮是判断按下了哪个按钮，首先要遵守 UIAlertViewDelegate 协议

 

重写方法：

 

```
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
     if(buttonIndex == 0){
        NSLog(@"The First Button Pressed");          
    }else if(buttonIndex == 1){
        NSLog(@"The Second Button Pressed");      
   }else{
.....
}
```

 判断buttonIndex的值即可。