//在APPDelegate.h中,即項目的入口部分
//didFinishLaunchingWithOptions該方法表示APP啟動完畢,接下來進入自定義界面
//如下MyViewController是自定義的類,即一個界面實現UIViewController接口
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
MyViewController *myController = [[MyViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}//MyViewController.h
//定義四個控件
@interface MyViewController : UIViewController
@property (strong, nonatomic) UILabel *labelNum;
@property (strong, nonatomic) UILabel *labelPwd;
@property (strong, nonatomic) UITextField *fieldNum;
@property (strong, nonatomic) UITextField *fieldPwd;
@end
//MyViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.labelNum = [[UILabel alloc] init];
self.labelNum.frame = CGRectMake(100, 100, 50, 20);
self.labelNum.text = @"Num: ";
self.fieldNum = [[UITextField alloc] init];
self.fieldNum.frame = CGRectMake(150, 100, 100, 20);
self.fieldNum.borderStyle = UITextBorderStyleRoundedRect;
self.labelPwd = [[UILabel alloc] init];
self.labelPwd.frame = CGRectMake(100, 150, 50, 20);
self.labelPwd.text = @"Pwd: ";
self.fieldPwd = [[UITextField alloc] init];
self.fieldPwd.frame = CGRectMake(150, 150, 100, 20);
self.fieldPwd.borderStyle = UITextBorderStyleRoundedRect;
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 200, 80, 20);
btn.backgroundColor = [UIColor grayColor];
[btn setTitle:@"login" forState:UIControlStateNormal];
//設置按鈕監聽事件,監聽方法為login
[btn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:self.labelNum];
[self.view addSubview:self.fieldNum];
[self.view addSubview:self.labelPwd];
[self.view addSubview:self.fieldPwd];
[self.view addSubview:btn];
}//頁面跳轉,并傳遞參數
-(void) login{
NSLog(@"login");
NSString *num = self.fieldNum.text;
NSString *pwd = self.fieldPwd.text;
if([num isEqualToString:@"123"] == TRUE){
NSLog(@"yes");
//初始化要跳轉的界面
MainViewController *mm = [[MainViewController alloc] init];
//把賬號密碼傳遞到下個界面
[mm initData:num two:pwd];
//開始跳轉
[self.navigationController pushViewController:mm animated:FALSE];
}else{
NSLog(@"error");
}
}//MainViewController.h
@interface MainViewController : UIViewController //@property( nonatomic) NSString //傳遞兩個參數a、b NSString 類型 -(void) initData:(NSString *) a two:(NSString *) b; @end
//接收參數,并保存
-(void) initData:(NSString *) a two:(NSString *) b{
self.num = a;
self.pwd = b;
NSLog(@"%@,%@", self.num, self.pwd);
}//效果圖


免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。