gpt4 book ai didi

iOS - 转到带有 if 条件的页面

转载 作者:行者123 更新时间:2023-11-28 19:52:02 24 4
gpt4 key购买 nike

我想在用户输入正确的用户名和密码后转到其他页面。怎么做 ?第一个菜单是 ViewController。第二种观点是 Utama。用户名从 username NSString 中获取,密码从 password NSString 中获取。

正确的用户名是“Andika”,正确的密码是 1234。

Storyboard enter image description here

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

乌塔玛.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.
}
*/

更新:对不起,我是新手。我仍然无法转到另一页。

我这样给标识符 enter image description here

这是修改ViewController.m中的代码 enter image description here

最佳答案

您可以像这样实例化 Utama

Utama *vc = [[UIStoryboard storyboardWithName:@"nameOfStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"Utama"];

如果ViewControllerUINavigationController上,你可以使用

[self.navigationController pushViewController:vc animated:YES]

但是,如果 ViewController 是窗口的 rootViewController,您可以将 vc 设置为 rootViewController

[window setRootViewController:vc];

确保 window 是您应用的关键窗口的实例。

关于iOS - 转到带有 if 条件的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28668940/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com