我是一个 xcode 菜鸟,但这是我正在寻找的内容,然后是我所做的事情。我创建了一个登录名,并使用该登录名 usernameField 我正在尝试验证用户并仅打开一个特定于该人的网页。登录工作在这里是我的所有代码
//LoginViewController.h
#import <UIKit/UIKit.h>
@interface LoginViewController : UIViewController
{
IBOutlet UITextField *usernameField;
IBOutlet UITextField *passwordField;
IBOutlet UIButton *loginButton;
IBOutlet UIActivityIndicatorView *loginIndicator;
}
@property(nonatomic, strong) UITextField *usernameField;
@property(nonatomic, strong) UITextField *passwordField;
@property(nonatomic, strong) UIButton *loginButton;
@property(nonatomic, strong) UIActivityIndicatorView *loginIndicator;
-(IBAction) login: (id) sender;
@end
//LoginViewController.m
#import "LoginViewController.h"
@implementation LoginViewController
@synthesize usernameField, passwordField, loginButton, loginIndicator;
-(IBAction) login: (id) sender
{
if ([usernameField.text isEqualToString: @"userOne"] && [passwordField.text
isEqualToString: @"passwordOne"])
{
printf("Success")
//here is where I would like to pass usernameField.text to WebViews
}
else if (([usernameField.text isEqualToString: @"userTwo"] && [passwordField.text
isEqualToString: @"passwordTwo"])
{
printf("Success")
//here is where I would like to pass usernameField.text to WebViews
}
else
{
printf("Login Failed")
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login Failed"
message:@"Wrong username and password" delegate:self
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
[alert show];
}
loginIndicator.hidden=False;
[loginIndicator startAnimating];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"fromLogin"])
{
WebViews *wvc = [segue destinationViewController];
wvc.usernamerField = self.usernameField.text;
}
}
@end
//WebViews.h
@interface WebViews : UIViewController
{
IBOutlet UIWebView *webView;
NSString *usernameField;
}
@property (nonatomic, strong) NSString*usernameField;
@end
//WebViews.m
#import "WebViews.h"
@interface WebViews ()//To be honest I'm not sure what this is for
@end
@implementation WebViews
@synthesize usernameField;
-(void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"username is = %@", self.usernameField);
if([T.usernameField.text isEqualToString: @"userOne"])
{
[webView loadRequest: [NSURLRequest requestWithURL: [NSURL
URLWithString:@"http://www.google.com"]]];
}
else if([T.usernameField.text isEqualToString: @"userTwo"])
{
[webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.yahoo.com"]]];
}
else
{
[webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.wikipedia.com"]]];
}
@end
任何帮助是极大的赞赏