码迷,mamicode.com
首页 > 其他好文 > 详细

【UIKit】UIAlert,UIActionSheet

时间:2014-08-05 00:21:28      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:des   blog   http   使用   io   2014   ar   cti   

【Alert】

bubuko.com,布布扣

 

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

【UIKit】UIAlert,UIActionSheet

标签:des   blog   http   使用   io   2014   ar   cti   

原文地址:http://www.cnblogs.com/iflewless/p/3891167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!