//按鈕事件
-(IBAction)btnRead
{
UIAlertView* a=[[UIAlertViewalloc]init];
a=[[UIAlertViewalloc] initWithTitle:@"b"message:@"s"delegate:selfcancelButtonTitle:@"確定"otherButtonTitles: @"取消",nil];
[a show];
}
//定義的委托,buttonindex就是按下的按鈕的index值
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%i",buttonIndex);
}
摘自 凡娃軟件