【UIKit】UIAlert,UIActionSheet

【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);
  }
}

转载于:https://www.cnblogs.com/iflewless/p/3891167.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值