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

UIKit 框架之UIAlertView

时间:2015-05-18 18:21:45      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:

//
//  ViewController.m
//  UIAlertView
//
//  Created by City--Online on 15/5/18.
//  Copyright (c) 2015年 XQB. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIAlertViewDelegate>
@property(nonatomic,strong) UIAlertView *alertView;
@property(nonatomic,strong) UIAlertView *alertView1;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _alertView=[[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil ];
//    typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
//        UIAlertViewStyleDefault = 0,    无文本框
//        UIAlertViewStyleSecureTextInput, 密码样式
//        UIAlertViewStylePlainTextInput,  普通样式
//        UIAlertViewStyleLoginAndPasswordInput  两个文本框
//    };
    _alertView.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;
    //添加按钮
    [_alertView addButtonWithTitle:@"YES"];
    //获取弹出框按钮的个数并遍历
    for (int i=0; i<_alertView.numberOfButtons; i++) {
        //根据索引值获取按钮的标题
        NSLog(@"i=%d  %@",i,[_alertView buttonTitleAtIndex:i]);
    }
   
    //获取第一个其他按钮的索引
    NSLog(@"firstOtherButtonIndex=%ld",[_alertView firstOtherButtonIndex]);
    _alertView.tag=10001;
    //弹出视图
    [_alertView show];
    
    _alertView1=[[UIAlertView alloc]initWithTitle:@"提示" message:@"是否退出?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
    
    _alertView1.tag=10002;
    [_alertView1 show];
    
}

//UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==10002) {
        //当我点击_alertView1的取消按钮时则同时完成点击_alertView的取消按钮
        if (buttonIndex==0) {
            //程序自动完成点击buttonIndex的button 并dismiss 整个alertView的操作
            [_alertView dismissWithClickedButtonIndex:0 animated:YES];
        }
    }
    else
    {
        if (buttonIndex==1) {
            //获取文本框
            UITextField *textField1=[_alertView textFieldAtIndex:0];
            NSLog(@"%@",textField1.text);
            
            UITextField *textField2=[_alertView textFieldAtIndex:1];
            NSLog(@"%@",textField2.text);
        }
       
    }
}

- (void)alertViewCancel:(UIAlertView *)alertView
{
    NSLog(@"alertViewCancel");
}
//视图显示前
- (void)willPresentAlertView:(UIAlertView *)alertView;
{
    NSLog(@"willPresentAlertView");
}
//视图显示后
- (void)didPresentAlertView:(UIAlertView *)alertView
{
    NSLog(@"didPresentAlertView");
}
//视图消失前
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
     NSLog(@"willDismissWithButtonIndex");
}
//视图消失后
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"didDismissWithButtonIndex");

}
//第一个FirstOtherButton是否可用
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    if (alertView.tag==10001) {
        return NO;
    }
    else
    {
        return YES;
    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 技术分享技术分享技术分享

UIKit 框架之UIAlertView

标签:

原文地址:http://www.cnblogs.com/cuiyw/p/4512219.html

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