2013-8-12练习[制作一个具有UIAlertView和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

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值