---
title: ios 第四週 0626
tags: ios
---
> [👩💻 回主頁](https://hackmd.io/@janice-code/after_school_ios)
## icon 設置
> [App Icon Generator](https://appicon.co/)
> [教學參考](https://medium.com/彼得潘的-swift-ios-app-開發教室/ios-app-icon-製作工具-62a01fcf1aac)






---
## 建立子畫面




> 介面我稍微排了一下

將元件連到程式區塊
``` h
//
// LoginSucess.h
// LogIn
//
// Created by janice on 2021/6/29.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface LoginSucess : UIViewController
{
UILabel *label;
UILabel *username;
}
@property (strong, nonatomic) IBOutlet UILabel *labeluser;
@property (strong, nonatomic) IBOutlet UILabel *labelpwd;
@property (strong) NSString *userid;
@property (strong) NSString *userpwd;
@property (weak, nonatomic) IBOutlet UIButton *goBackButton;
@end
NS_ASSUME_NONNULL_END
```
```m
//
// LoginSucess.m
// LogIn
//
// Created by janice on 2021/6/29.
//
#import "LoginSucess.h"
@interface LoginSucess ()
@end
@implementation LoginSucess
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"_userid>%@", _userid);
NSLog(@"_userpwd>%@", _userpwd);
[_labeluser setText:_userid];
[_labelpwd setText:_userpwd];
// Do any additional setup after loading the view from its nib.
}
/*
#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.
}
*/
@end
```
## 實作
### 新增按鈕
```m
UIAlertAction* ShowButton = nil;
ShowButton = [UIAlertAction actionWithTitle:@"哈哈" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){}];
[alertController addAction: ShowButton];
```
### 頁面跳轉
```m
#import "LoginSucess.h"
LoginSucess *loginsucess = [[LoginSucess alloc] initWithNibName: @"LoginSucess" bundle:nil];
loginsucess.userid = InputId;
loginsucess.userpwd = InputPassword;
[self presentViewController:loginsucess animated:YES completion:nil];
```
### 完整程式
```m
//
// ViewController.m
// LogIn
//
// Created by janice on 2021/6/12.
//
#import "ViewController.h"
#import "LoginSucess.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet NSString *username;
@property (weak, nonatomic) IBOutlet NSString *password;
@property (weak, nonatomic) IBOutlet UITextField *usernameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.username = @"user";
self.password = @"1234";
self.usernameTextField.text = self.username;
self.passwordTextField.text =self.password;
}
- (IBAction)LogIn:(id)sender {
NSString *InputId = self.usernameTextField.text; // 輸入帳號 user
NSString *InputPassword = self.passwordTextField.text; // 輸入密碼 1234
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"登入" message:[NSString stringWithFormat:@"%@", InputId] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ShowButton = nil;
UIAlertAction* ShowButton2 = nil;
if([self.username isEqualToString: InputId] && [self.password isEqualToString: InputPassword]){
[alertController setMessage:[NSString stringWithFormat: @"%@ 登入成功", InputId]];
ShowButton = [UIAlertAction actionWithTitle:@"哈哈" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
LoginSucess *loginsucess = [[LoginSucess alloc] initWithNibName: @"LoginSucess" bundle:nil];
loginsucess.userid = InputId;
loginsucess.userpwd = InputPassword;
[self presentViewController:loginsucess animated:YES completion:nil];
}];
ShowButton2 = [UIAlertAction actionWithTitle:@"呵呵" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
}];
}else{
[alertController setMessage:[NSString stringWithFormat:@"%@ 登入失敗", InputId]];
ShowButton = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
}];
}
[alertController addAction: ShowButton];
[alertController addAction: ShowButton2];
[self presentViewController:alertController animated:YES completion:nil];
}
@end
```
