我想在用户插入正确的用户名和正确的密码后转到其他页面。怎么做 ? 第一个菜单是 ViewController 。第二种观点是 Utama 。用户名来自用户名NSString ,密码来自密码NSString 。
正确的用户名是" Andika"正确的密码是1234。
故事板
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *appTittle;
@property (weak, nonatomic) IBOutlet UITextField *usernameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
- (IBAction)okPressed:(id)sender;
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)okPressed:(id)sender {
NSString *username = [_usernameTextField text];
NSString *password = [_passwordTextField text];
if([username compare:@"andika"] && [password compare:@"1234"]) {
//????
}
}
@end
Utama.m
#import "Utama.h"
@interface Utama ()
@end
@implementation Utama
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
更新:对不起,我是新手。我仍然无法访问另一页。
我给这样的标识符
这是ViewController.m中的修改代码
答案 0 :(得分:2)
您可以像这样实例化Utama
。
Utama *vc = [[UIStoryboard storyboardWithName:@"nameOfStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"Utama"];
如果ViewController
上有UINavigationController
,您可以使用
[self.navigationController pushViewController:vc animated:YES]
但是,如果ViewController
是窗口的rootViewController,则可以将vc
设置为rootViewController
。
[window setRootViewController:vc];
确保window
是应用关键窗口的实例。
答案 1 :(得分:1)
Utama 是一个uitabbarcontroller对吧!?如果您想在单击确定时转到第0个选项卡,请提供类似于&#34; DummyTab &#34;的标识符。到Utama视图并使用下面的代码:
UITabBarController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DummyTab"];
[self.navigationController pushViewController:controller animated:YES];
[controller setSelectedIndex:0];
答案 2 :(得分:0)
使用此代码段解决您的问题:
Utama *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Utama"];
[self.navigationController pushViewController:controller animated:YES];
答案 3 :(得分:0)
您需要嵌入导航控制器,即添加导航控制器并将其设置为初始视图控制器,并将登录视图控制器设置为导航控制器的根视图控制器,然后在成功凭据检查后,您可以按下面的其他视图控制器
- (IBAction)okPressed:(id)sender {
NSString *username = [_usernameTextField text];
NSString *password = [_passwordTextField text];
if([username compare:@"andika"] && [password compare:@"1234"]) {
[self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"Utama storyboard identifier" animated:YES];
//also remove login view from stack
[self removeFromParentViewController];
}
}
答案 4 :(得分:0)
- (IBAction)okPressed:(id)sender
{
NSString *username = [_usernameTextField text];
NSString *password = [_passwordTextField text];
if ([username isEqualToString:@"andika"] == YES && [password isEqualToString:@"1234"] ==YES )
{
Utama *NextView = [[Utama alloc]initWithNibName:@"Utama" bundle:nil];
[self.navigationController pushViewController:NextView animated:YES];
}
}