AdminViewController
如果我输入了错误的用户名或密码,我有一个 PasswordViewController 会提示我,但是当按下 Enter 按钮时我无法加载它;它带来了一个黑屏。
密码视图控制器.h
#import <UIKit/UIKit.h>
#import "AdminViewController.h"
@interface PasswordViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *username;
@property (strong, nonatomic) IBOutlet UITextField *password;
- (IBAction)enterButton:(id)sender;
@end
NSDictionary *passwordDictionary;
密码视图控制器.m
#import "PasswordViewController.h"
@interface PasswordViewController ()
@end
@implementation PasswordViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
passwordDictionary = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"password", nil] forKeys:[NSArray arrayWithObjects:@"username", nil]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)enterButton:(id)sender {
if ([[passwordDictionary objectForKey:_username.text]isEqualToString:_password.text]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct Password" message:@"This password is correct." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
AdminViewController *secondView = [[AdminViewController alloc] init];
[self presentViewController:secondView animated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Incorrect Password" message:@"This password is incorrect" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}
}
@end
AdminViewController.h
@interface AdminViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@end
AdminViewController.m
#import "AdminViewController.h"
@interface AdminViewController ()
@end
@implementation AdminViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *myURL = [NSURL URLWithString:@"http://www.google.co.uk"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[_webView loadRequest:myRequest];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end