我对Objective-C很陌生,所以希望这一切都有意义。此处在验证用户名和密码字段后会UIAlertView
弹出。我想要的是当用户按下UIAlertViewButton
. 控件应导航到指令视图控制器。
但在这里它不起作用
这是.h文件代码:
#import <UIKit/UIKit.h>
#import "InstructionBIDViewController.h"
@interface SignInViewController : UIViewController<UIAlertViewDelegate>{
IBOutlet UITextField *usernamefield;
IBOutlet UITextField *password;
NSDictionary *creditialDictionary;
}
@property (strong, nonatomic) InstructionBIDViewController *viewControllerinst;
-(IBAction)enterCredential;
//-(void) submitData;
@end
这是 .m 文件代码:
#import "SignInViewController.h"
#import "InstructionBIDViewController.h"
@interface SignInViewController ()
@end
@implementation SignInViewController
@synthesize viewControllerinst;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//[self submitData];
creditialDictionary =
[[NSDictionary alloc ] initWithObjects:
[NSArray arrayWithObjects:@"password",@"1234",nil]
forKeys:
[NSArray arrayWithObjects:@"username", @"alex",nil]];
}
-(IBAction)enterCredential
{
if ([[creditialDictionary objectForKey:usernamefield.text]
isEqualToString:password.text]) {
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@"Correct Password"
message:@"This password is correct"
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@"InCorrect Password"
message:@"This password is incorrect"
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
}
}
//-(void) alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex{
//Here the functionality that i want to perform ...but it is not working
- (void)alertView:(UIAlertView *)alertView
didDismissWithButtonIndex:(NSInteger)buttonIndex{
// u need to change 0 to other value(,1,2,3) if u have more buttons.
// then u can check which button was pressed.
if (buttonIndex == alertView.cancelButtonIndex) {
// Cancelled
viewControllerinst = [[InstructionBIDViewController alloc]
initWithNibName:@"InstructionBIDViewController" bundle:nil];
[self.navigationController pushViewController:viewControllerinst
animated:YES];
}
}
@end
请帮助我使用UIAlertView
?