【Alert】

1.加入协议
<UIAlertViewDelegate,UIActionSheetDelegate>
2.
-(IBAction)btnShowAlertView:(id)sender
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"标题"
message:@"对话框的内容"
delegate:self
cancelButtonTitle:@"关闭"
otherButtonTitles:@"其他1",@"其他2",nil];
[alert show];
[alert release];
}
3.如何获取到点击按钮的tag
#pragma mark - UIAlertViewDelegate可以获取到所按的按钮的index
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet buttonIndex = %i", buttonIndex);
}
【sheet】
1.加入协议
<UIAlertViewDelegate,UIActionSheetDelegate>
2.
-(IBAction)btnShowActionSheet:(id)sender
{
UIActionSheet *actions=[[UIActionSheet alloc]initWithTitle:@"标题"
delegate:self
cancelButtonTitle:@"关闭"
destructiveButtonTitle:nil
otherButtonTitles:@"其他1",@"其他2", nil];
[actions showInView:self.view];
[actions release];
}
3.获取到sheet点击按钮的index
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet buttonIndex = %i", buttonIndex);
}
【SVStatusHUD】 第三方Alert
-(IBAction)btnStatusHUD:(id)sender
{
[SVStatusHUD showSuccessWithStatus:@"授权已过期!"];
}
操作步骤:
1.在.m中引用
#import "SVStatusHUD.h"
2.加入代码
-(IBAction)btnStatusHUD:(id)sender
{
[SVStatusHUD showSuccessWithStatus:@"授权已过期!"];
}
【嵌套的Alert】
#pragma mark -循环提问
-(IBAction)btnShowAlertView:(id)sender
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"标题"
message:@"对话框的内容"
delegate:self
cancelButtonTitle:@"关闭"
otherButtonTitles:@"其他1",@"其他2",nil];
alert.tag=1; // 【使用tag值进行嵌套跳出】
[alert show];
[alert release];
}
#pragma mark - UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag==1) // 【判断如果tag==1,那么就继续第二层,然后在本方法中设置tag为2,当再次进入此循环后,tag!=1就可以跳出循环了】
{
NSLog(@"actionSheet buttonIndex = %i", buttonIndex);
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"标题2"
message:@"对话框的内容2"
delegate:self
cancelButtonTitle:@"关闭2"
otherButtonTitles:@"第二层2",@"第二层1",nil];
alert.tag=2;
[alert show];
[alert release];
}
else
{
NSLog(@"actionSheet buttonIndex = %i", buttonIndex);
}
}
【UIKit】UIAlert,UIActionSheet,布布扣,bubuko.com
原文:http://www.cnblogs.com/iflewless/p/3891167.html