AppDelegate.h
<pre name="code" class="objc"><span style="font-size: 18px;">#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate, UITextFieldDelegate, UIAlertViewDelegate></span>
<span style="font-size: 18px;">@property (retain, nonatomic) UIWindow *window;</span>
<span style="font-size: 18px;">@end</span>
AppDelegate.m
<span style="font-size:18px;">@interface AppDelegate ()
// 设置属性为了alert
@property (retain, nonatomic) UITextField *greenView2;
@property (retain, nonatomic) UITextField *blueView2;
@property (retain, nonatomic) UIButton *redView1;
@property (retain, nonatomic) UIView *loginContainerView;
@property (retain, nonatomic) UIView *registContainerView;
@property (retain, nonatomic) UIView *passwordContainerView;
@property (retain, nonatomic) UITextField *nameImport;
@property (retain, nonatomic) UITextField *passwordImport;
@property (retain, nonatomic) UITextField *passwordImportAgain;
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
// 回收键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
// 添加alert
// 1.登陆界面
- (void)alertViewShow1
{
NSLog(@"greenView2 %@ blueView2 %@", self.greenView2.text, self.blueView2.text);
if ([self.greenView2.text isEqualToString:@"我"] && [self.blueView2.text isEqualToString:@"123"])
{
UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"欢迎回来" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alertView1 show];
[alertView1 release];
}
else
{
UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或者密码错误,请核对后再试" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alertView2 show];
[alertView2 release];
}
}
// 2.注册界面
- (void)alertViewShow2
{
if ([self.passwordImport.text isEqualToString:self.passwordImportAgain.text] && self.nameImport.text.length != 0 && self.passwordImport.text.length != 0 && self.passwordImportAgain.text.length != 0)
{
UIAlertView *alertView3 = [[UIAlertView alloc] initWithTitle:@"注册成功" message:@"大家庭欢饮您" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alertView3 show];
[alertView3 release];
}
else if (self.nameImport.text.length == 0 || self.passwordImport.text.length == 0 || self.passwordImportAgain.text.length == 0)
{
UIAlertView *alertView4 = [[UIAlertView alloc] initWithTitle:@"注册失败" message:@"用户名密码或确认密码不能为空" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alertView4 show];
[alertView4 release];
}
els