2013-8-12练习[制作一个具有UIAlertView和UIActionSheet的登陆界面]

简介: 创建登陆窗口(有用户名和密码),确认后弹出对话框再输入一遍,如果都相同,显示用户图片,如果不相同,弹出上拉菜单(UIActionSheet),问是否重新输入,是的话弹出对话框重新输入。

创建登陆窗口(有用户名和密码),确认后弹出对话框再输入一遍,如果都相同,显示用户图片,如果不相同,弹出上拉菜单(UIActionSheet),问是否重新输入,是的话弹出对话框重新输入。

效果图:


viewController.h:

//
//  DXWViewController.h
//  2013-8-12作业
//
//  Created by 丁小未 on 13-8-12.
//  Copyright (c) 2013年 dingxiaowei. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface DXWViewController : UIViewController<UIAlertViewDelegate,UIActionSheetDelegate>
@property (retain, nonatomic) IBOutlet UITextField *lblName;
@property (retain, nonatomic) IBOutlet UITextField *lblPassword;
- (IBAction)Check:(id)sender;
@property (retain, nonatomic) IBOutlet UIImageView *image;
- (IBAction)clickKeyBoardReturn:(id)sender;
@property (retain, nonatomic) IBOutlet UILabel *lblState;

@end

ViewController.m:

//
//  DXWViewController.m
//  2013-8-12作业
//
//  Created by 丁小未 on 13-8-12.
//  Copyright (c) 2013年 dingxiaowei. All rights reserved.
//

#import "DXWViewController.h"
#import "MyDelegate.h"
NSString *nameT;
NSString *pwdT;
@interface DXWViewController ()

@end

@implementation DXWViewController

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 0)
    {
       NSLog(@"重试");
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"身份验证" message:@"请输入用户名和密码" delegate:self cancelButtonTitle:@"登陆" otherButtonTitles:@"取消",nil];
        alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
        
        [alert show];
        [alert release];
    }
    else if(buttonIndex == 1)
    {
        NSLog(@"取消");
    }
}

//实现协议
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"didDismissWithButtonIndex %d",buttonIndex);
    NSLog(@"%@",[alertView textFieldAtIndex:0].text);
    NSLog(@"%@",[alertView textFieldAtIndex:1].text);
    nameT = [alertView textFieldAtIndex:0].text;
    pwdT = [alertView textFieldAtIndex:1].text;
    NSString *na = self.lblName.text;
    NSString *pw = self.lblPassword.text;
    if (buttonIndex == 0) {
    //相同为0,不同为-1
    if ([nameT compare:na]==0 && [pwdT compare:pw]==0)
    {
        //登陆成功显示图片
        NSLog(@"登陆成功!");
        self.lblState.text = @"登陆成功,酷狗来也!";
        self.image.hidden = false;
        self.lblState.hidden = false;
    }
    else
    {
        self.image.hidden = true;
        self.lblState.text = @"登陆失败!";
        self.lblState.hidden = false;
        NSLog(@"登陆失败!");

        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择框" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"重试" otherButtonTitles:nil];
        sheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        [sheet showInView:self.view];
     }
    }
    else if(buttonIndex == 1)
    {
        
        NSLog(@"取消");
    }
}


- (void)viewDidLoad
{
    [super viewDidLoad];
	self.image.hidden = YES;//将头像图片隐藏
    [self.lblName becomeFirstResponder];//设置为第一响应者
    self.lblState.hidden = YES;//隐藏消息栏
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}

- (void)dealloc {
    [_lblName release];
    [_lblPassword release];
    [_image release];
    [_lblState release];
    [super dealloc];
}

- (IBAction)Check:(id)sender {
//    MyDelegate *delegate = [[MyDelegate alloc]init];

    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"身份验证" message:@"请输入用户名和密码" delegate:self cancelButtonTitle:@"登陆" otherButtonTitles:@"取消",nil];
    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    
    [alert show];
    [alert release];

}
- (IBAction)clickKeyBoardReturn:(id)sender {
    [self.lblName resignFirstResponder];
    [self.lblPassword resignFirstResponder];
    
}
@end

如果允许让屏幕横屏:

//是否可以自动横屏
-(BOOL)shouldAutorotate
{
    return YES;
}
//可以各个方向横屏
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

//每当屏幕旋转的时候都会触发一个

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{

    //如果是是横屏状态

    if(toInterfaceOrientation ==UIInterfaceOrientationLandscapeLeft ||toInterfaceOrientation ==UIInterfaceOrientationLandscapeRight)

    {

    }

    else

    {

    }


如果要设置系统启动时就是横屏,可以修改plist文件Supportd interface orientations的Item的顺序,如果item0是横屏,那就是横屏启动,在项目运行的时候,可以点击command+左右键

项目源文件:http://download.csdn.net/detail/s10141303/5923513

相关文章
UIActionSheet,UIAlertView,UIAlertController的详细说明
UIActionSheet,UIAlertView,UIAlertController的详细说明
98 0
UIActionSheet,UIAlertView,UIAlertController的详细说明
|
数据安全/隐私保护
MBProgressHUD中间转圈来提高用户的体验
MBProgressHUD中间转圈来提高用户的体验
143 0
MBProgressHUD中间转圈来提高用户的体验
|
iOS开发
UIImagePickerController显示中文界面
iOS开发中,我们经常遇到获取拍照、相册中图片的功能,就必然少不了UIImagePickerController,但是我们发现当我们使用它的时候,它的页面是英文的,看着很别扭,国人还是比较喜欢看中文界面,下面来看看我们怎么把它变成中文界面的吧!
UIImagePickerController显示中文界面
|
iOS开发 索引
IOS UIAlertView(警告框)方法总结
IOS UIAlertView(警告框)方法总结
139 0
IOS UIAlertView(警告框)方法总结
|
iOS开发
iOS开发UINavigation系列三——工具栏UIToolBar
iOS开发UINavigation系列三——工具栏UIToolBar
144 0
iOS开发UINavigation系列三——工具栏UIToolBar

热门文章

最新文章