UIApplication

- (void) testUIApplication {// Singleton UIApplication *app = [UIApplication shareApplication]; / / Settings icon notification number / / - ios9 above need to set up notifications UIUserNotificationCategory * category = [[UIUserNotificationCategory alloc] init]; NSSet *set = [NSSet setWithObject:category]; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsTypes:UIUserNotificationTypeBadge categore:set]; [app registerUserNotificationSettings:setting]; / / set number, 0 does not display the app. ApplicationIconBadgeNumber = 10; / / set the network status indicator app.net workActivityIndicatorVisible = YES; // Call/send SMS/email/jump to other app interface // [app openURL:]; [View Controller-based status bar appearance] = NO // Control by controller app.statusBarHidden = YES; / / hide status bar app. StatusBarStyle = UIStatusBarStyleLightContent; } -(BOOL) prefersStatusBarHidden {// [View controller-based status bar appearance] = YES, Return YES; }Copy the code

Application Startup Process

Application startup process: 1. Entry main.m main function 2. Create automatic release pool 3. Run UIApplicationMain in an infinite loop 4. Third argument nil: equivalent to @"UIApplication" to create an application object 5. Apply proxy object 6. Instantiate UIWindow in the application proxy object and set it to keyWindow 7 of the application. @implementation AppDelegate - (BOOL) application:(UIApplication *) Application didFinishLaunchingWithOPtions: (launchOptions NSDictionary *) {/ / application loaded return YES; } - (void) applicationWillResignActive application: (UIApplication *) {/ / is about to become inactive [loses focus]} - (void) ApplicationDidEnterBackground: (application UIApplication *) {/ / application / / into the background here save state and data} - (void) ApplicationWillEnterForeground: (UIApplication *) application into the foreground} {/ / application - (void) ApplicationDidBecomeActive: (UIApplication *) application {/ / is about to become active [focus]} - (void) Application applicationWillTerminate: (UIApplication *) {/ / / / application is destroyed not necessarily execution, hold down the home to the background, application or scratch out a period of time, do not perform} @ the endCopy the code

Create UIWindow manually

UIWindow *win = [[UIWindow alloc] initWithFrame:CGRectMake(20, 20, 200, 200)]; win.backgroundColor = [UIColor redColor]; win.hidden = NO; [self.view addSubview:win]; // UIWinow is hidden by default and must be set to unhidden to display. UIWindow [[[UIApplication sharedApplication]. Windows lastObject] addSubview:win]; // on ios13 and above, keep SceneDelegate, - (void)scene:(UIScens *)scene willConnectToSession:(UISeccion *)session options:(UISceneConnecionOptions *)connectionOptions { if(@available(ios 13, *) && scene) { self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene]; self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ViewController *viewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"index"]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController]; self.window.rootViewController = nav; [self.window makeKeyAndVisible]; }} // For iOS13: // a. Delete the Application Scene Manifest option in the info.plist file; // b. Delete SceneDelegate; // c. Delete AppDelegate UISceneSession lifecycle; // add the window attribute to the AppDelegate header; @property (strong, nonatomic) UIWindow *window; E. Modify the AppDelegate startup method:  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; ViewController *vc = [[ViewController alloc]init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; self.window.rootViewController = nav; [self.window makeKeyAndVisible]; return YES; }Copy the code

Loading custom ViewController (code, storyboard, XIB)

#import <UIKit/ uikit. h> @interface AppDelegate: UIResponder <UIApplicationDelegate> @end // 1. Create ViewController @interface AppDelegate () @implementation AppDelegate - (BOOL) application:(UIApplication *) application didFinishLaunchingWithOPtions:(NSDictionary *) launchOptions { // 1. Create window self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bound]; CTViewController = [[CTViewController alloc] init]; / / 2.2 Settings window controller self. The root of the window. The rootViewController = viewController; // 3. Set the window to the main window of the application and set it to VIsible [VIsible] [self.window makeKeyAndVisible]; // [self.window makeKeyWindow]; // self.window.hidden = NO; return YES; } @interface AppDelegate () @implementation AppDelegate - (BOOL) application:(UIApplication *) application didFinishLaunchingWithOPtions:(NSDictionary *) launchOptions { // 1. Create window self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bound]; 2.1.1 Creating a storyboard file, 2.1.2 Loading storyboard UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"CTStroryboard" bundle:nil]; // A storyboard can have multiple controllers, The default to load the last / / UIViewController * viewController = [storyboard instantiateInitialViewController]; // Configure the controller Identifier in the storyboard, The specified control UIViewController * viewController = [storyboard instantiateViewControllerWithIdentifier: @ "login"); Self. rootViewController = viewController; // 3. Set the window to the main window of the application and set it to VIsible [VIsible] [self.window makeKeyAndVisible]; // [self.window makeKeyWindow]; // self.window.hidden = NO; return YES; } @interface AppDelegate () @implementation AppDelegate - (BOOL) application:(UIApplication *) application didFinishLaunchingWithOPtions:(NSDictionary *) launchOptions { // 1. Create window self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bound]; Xib = CTViewController; xiB = CTViewController; xiB = CTViewController The system preferentially finds the xiB (ctViewController.xib) that matches exactly. Xib (ctView.xib) // ViewController * ViewController = [[CTViewController alloc] init]; ViewController *viewController = [[CTViewController alloc] initWithNibName:@" XXX" bundle:nil]; Self. rootViewController = viewController; // 3. Set the window to the main window of the application and set it to VIsible [VIsible] [self.window makeKeyAndVisible]; // [self.window makeKeyWindow]; // self.window.hidden = NO; return YES; } @endCopy the code

Navigation bar controller UINavigationController controls multiple interface switches

UINavigationController *nav = [[UINavigationController alloc] init]; ControllerView UINavigationController *nav = [[UINavigationController alloc] initWithRootViewcontroller:[[ViewController alloc] init]]; 2. According to a controller under the [viewController navigationController pushViewController: [[viewController alloc] init] animated: YES]; 3. The return on a controller [viewController navigationController popToRootViewControllerAnimated: YES]; 4. Return to the specified controller. Can only be returned in the stack instance viewController. NavigationController. ViewControllers [viewController. NavigationController popToViewController:viewController animated:YES]; 5. Configuration navigation/titles/controller navigation viewController navigationItem. TitleView; / / controller back button UIBarButtonItem, following a back button viewController interface implementation. The navigationItem. BackBarButtonItem; / / the current interface viewController navigation bar on the left button. The navigationItem. LeftBarButtonItem; / / the current interface more than the navigation bar on the left button viewController. NavigationItem. LeftBarButtonItems; / / more than the current navigation bar on the right side of the interface button viewController navigationItem. RightBarButtonItems;Copy the code

UITabBarController (bottom TAB button + control multiple interface switching)

#import "SceneDelegate.h" @interface SceneDelegate () @end @implementation SceneDelegate - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene]; self.window.frame = [UIScreen mainScreen].bounds; UITabBarController *tabBarController = [[UITabBarController alloc] init]; self.window.rootViewController = tabBarController; UIViewController *vc1 = [[UIViewController alloc] init]; vc1.view.backgroundColor = [UIColor redColor]; Vc1. tabbaritem. title = @" red interface "; // vc1.tabBarItem.imagge = [UIImage imageNamed:@"xxx"]; vc1.tabBarItem.badgeValue = @"99"; UIViewController *vc2 = [[UIViewController alloc] init]; vc2.view.backgroundColor = [UIColor blueColor]; Vc2. Tabbaritem. title = @" blue interface "; // vc1.tabBarItem.imagge = [UIImage imageNamed:@"xxx"]; Vc2. TabBarItem. BadgeValue = @ "blue"; / / button to the top right corner shows [tabBarController addChildViewController:'s vc1]; [tabBarController addChildViewController:vc2]; [self.window makeKeyAndVisible]; } @endCopy the code

Controller life cycle

#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super  viewDidLoad]; } - (void)viewWillAppear:(BOOL) Animated {[super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated {[super viewDidAppear:animated]; / / interface has displayed} - (void) viewWillDisappear: (BOOL) animated {[super viewWillDisappear: animated]; } / / interface would disappear - (void) viewDidDisappear: (BOOL) animated {[super viewDidDisappear: animated]; } - (void)dealloc {// viewControll destroy} - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {// controllerView passes values} @end // Controllers A, B and C are displayed in sequence. When C returns A, B and C are destroyed in sequence. // Quickly change the default controllerView of storyboard to navigationController // Select Controller -> Editor -> Embed in -> Navigation ControllerCopy the code

Save the file to sandbox and archive the model

// The text input field becomes the first responder [self.numberField becomeFirstResponder]; NSString *homePaht = NSHomeDirectory(); NSString *docPath = [homePath stringByAppendingString:@"/Documents"]; NSString *docPath = [homePath stringByAppendingPathComponent:@"Documents"]; / / use the search folders to find the document nsstrings * docPath = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory NSUserDomainMask, YES)[0]; / / save the file nsstrings * filePath = [docPath stringByAppendingPathComponent: @ "xx. Plist"]. NSArray *array = @["111", "222", "demacia "]; [array writeToFile:filePath atomically:YES]; / / read a file array = [NSArray arrayWithContentOfFile: filePath]; NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; // Add [preferences setObject:@"value" forKey:@"key"]; [preferences setBool:YES forKey:@"boolKey"]; // [preferences synchronize]; // Get NSString *value = [preferences objectForKey:@"key"]; // Get NSString *value = [preferences objectForKey:@"key"]; BOOL boolKey = [preferences boolForKey:@"boolKey"]; <-> NSDate @interface Person <NSSecureCoding> @property(nonatamic, copy) NSString *name; @property(nonatamic, assign) int *age; @end @implemention Persion - (instancetype)initWithCoder:(NSCoder *)coder { _name = [coder decodeObjectForKey:@"name"]; _age = [coder decodeIntForKey:@"age"]; } - (void)encodeWithCoder:(NSCoder)coder { [coder encodeObject:self.name forKey:@"name"]; [coder encodeInt:self.age forKey:@"age"]; } @end void main() { Person *person = [[Person alloc] init]; person.name = @"xxx"; person.age = 18; NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; NSString *personDataFilePath = [docPath stringByAppendingPathComponent:@"person.data"]; / / archive [NSKeyedArchiver archiveRootObject: person toFile: personDataFilePath]; / Person/solution file * newPerson = [NSKeyedUnarchiver unarchiveObject: personDataFilePath]; }Copy the code

TabBar inline Navigation

// IFContactModel.h
@interface IFContactModel : NSObject <NSSecureCoding>
    @property (nonatomic, copy) NSString *username;
    @property (nonatomic, copy) NSString *number;
@end
// IFContactModel.m
#import "IFContactModel.h"
@implementation IFContactModel
    - (instancetype)initWithCoder:(NSCoder *)coder {
        if (self = [super init]) {
            _username = [coder decodeObjectForKey:@"username"];
            _number = [coder decodeObjectForKey:@"number"];
        }
        return self;
    }
    - (void)encodeWithCoder:(NSCoder *)coder {
        [coder encodeObject:self.username forKey:@"username"];
        [coder encodeObject:self.number forKey:@"number"];
    }
    + (BOOL)supportsSecureCoding {
       return YES;
    }
@end



// LoginViewController.h
@interface LoginViewController : UIViewController
@end
// LoginViewController.m
#import "LoginViewController.h"
#import "JGProgressHUD.h"

#define kUsername @"kUsername"
#define kPassword @"kPassword"
#define kRememberPassowrd @"kRememberPassowrd"
#define kAutoLogin @"kAutoLogin"

#define preferences [NSUserDefaults standardUserDefaults]

#define isEmpty(str) str == nil || [str isEqualToString:@""]
#define isNotEmpty(str) str != nil && ![str isEqualToString:@""]

@interface LoginViewController ()
    @property (weak, nonatomic) IBOutlet UITextField *username;
    @property (weak, nonatomic) IBOutlet UITextField *password;
    @property (weak, nonatomic) IBOutlet UISwitch *rememberPassword;
    @property (weak, nonatomic) IBOutlet UISwitch *autoLogin;
    @property (weak, nonatomic) IBOutlet UIButton *btnLogin;
@end

@implementation LoginViewController
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        [self.username addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];
        [self.password addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];
        self.btnLogin.enabled = NO;

        self.autoLogin.on = [preferences boolForKey:kAutoLogin];
        self.rememberPassword.on = [preferences boolForKey:kRememberPassowrd];

        if ([preferences boolForKey:kRememberPassowrd]) {
            if (isNotEmpty([preferences objectForKey:kUsername])) {
                self.username.text = [preferences objectForKey:kUsername];
            }
            if (isNotEmpty([preferences objectForKey:kPassword])) {
                self.password.text = [preferences objectForKey:kPassword];
            }
            [self textChange];
        }

        if ([preferences boolForKey:kAutoLogin]) {
            [self login:self.btnLogin];
        } else {
            if (isEmpty(self.username.text)) {
                [self.username becomeFirstResponder];
            } else if (isEmpty(self.password.text)) {
                [self.password becomeFirstResponder];
            }
        }
    }

    - (void) textChange {
        // 当输入框内容改变
        self.btnLogin.enabled = (self.username.text.length > 0 && self.password.text.length > 0) ? YES : NO;
    }

    - (IBAction)rememberPasswordChange:(UISwitch *)sender {
        if (!sender.isOn) {
            [self.autoLogin setOn:NO animated:YES];
        }
        [preferences setBool:self.rememberPassword.isOn forKey:kRememberPassowrd];
        [preferences setBool:self.autoLogin.isOn forKey:kAutoLogin];
    }

    - (IBAction)autoLoginChange:(UISwitch *)sender {
        if (sender.isOn) {
            [self.rememberPassword setOn:YES animated:YES];
        }
        [preferences setBool:self.rememberPassword.isOn forKey:kRememberPassowrd];
        [preferences setBool:self.autoLogin.isOn forKey:kAutoLogin];
    }

    - (IBAction)login:(UIButton *)sender {
        __block JGProgressHUD *HUD = [[JGProgressHUD alloc]  initWithStyle:JGProgressHUDStyleDark];
        HUD.textLabel.text = @"Loading";
        [HUD showInView:self.view];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [HUD dismissAnimated:YES];
            if ([self.username.text isEqualToString:@"1"] && [self.password.text isEqualToString:@"1"]) {
                // 手动跳转
                [self performSegueWithIdentifier:@"login2account" sender:nil];

                if ([preferences boolForKey:kRememberPassowrd]) {
                    [preferences setObject:self.username.text forKey:kUsername];
                    [preferences setObject:self.password.text forKey:kPassword];
                }
            } else {
                // 提示账号或密码错误
                JGProgressHUD *errorView = [[JGProgressHUD alloc] initWithStyle:JGProgressHUDStyleDark];
                errorView.textLabel.text = @"账号或密码错误";
                errorView.indicatorView = [[JGProgressHUDErrorIndicatorView alloc] init];
                [errorView showInView:self.view];
                [errorView dismissAfterDelay:1.0];
            }
        });
    }
@end


// ContactTableViewController.h
#import <UIKit/UIKit.h>
@interface ContactTableViewController : UITableViewController
@end
// ContactTableViewController.m
#import "ContactTableViewController.h"
#import "AddContactViewController.h"
#import "EditContactViewController.h"
#import "IFContactModel.h"

#define kContactsPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"contacts.data"]

@interface ContactTableViewController () <AddContactDelegate, EditContactDelegate>
    @property (nonatomic, strong) NSMutableArray *contacts;
@end

@implementation ContactTableViewController
    - (void)viewDidLoad {
        [super viewDidLoad];

        self.contacts = [[NSMutableArray alloc] init];

        // 读取通讯录数据
        NSSet *set = [NSSet setWithArray:@[[NSArray class], [IFContactModel class]]];
        NSData *data = [NSData dataWithContentsOfFile:kContactsPath];
        NSArray *tempArray = [NSKeyedUnarchiver unarchivedObjectOfClasses:set fromData:data error:nil];
        [self.contacts addObjectsFromArray:tempArray];
    }

    #pragma mark - Table view data source

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return self.contacts.count;
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"contact" forIndexPath:indexPath];

        IFContactModel *model = self.contacts[indexPath.row];

        cell.textLabel.text = model.username;
        cell.detailTextLabel.text = model.number;

        return cell;
    }

    // 重写此方法开启侧滑删除功能, 点击删除时事件
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
        [self.contacts removeObjectAtIndex:indexPath.row];

        [self cacheContacts];

        // 刷新数据
        // [self.tableView reloadData];
        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
    }

    #pragma mark - Navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        if ([segue.destinationViewController isKindOfClass:[AddContactViewController class]]) {
            AddContactViewController * controller = (AddContactViewController *) segue.destinationViewController;
            controller.delegate = self;
        } else if ([segue.destinationViewController isKindOfClass:[EditContactViewController class]]) {
            EditContactViewController * controller = (EditContactViewController *) segue.destinationViewController;
            controller.delegate = self;
            controller.contact = self.contacts[self.tableView.indexPathForSelectedRow.row];
        }
    }

    - (IBAction)logout:(UIBarButtonItem *)sender {
        // UIAlertControllerStyleAlert 弹框, UIAlertControllerStyleActionSheet 底部弹框
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否确认注销?" message:@"注销后将返回登录" preferredStyle:UIAlertControllerStyleActionSheet];
        // 2.创建并添加按钮
        UIAlertAction *logoutAction = [UIAlertAction actionWithTitle:@"注销" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            [self.navigationController popViewControllerAnimated:YES];
        }];
        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
        [alert addAction:logoutAction];
        [self presentViewController:alert animated:YES completion:^{}];
    }

    #pragma mark - AddContactDelegate
    - (void) addContactWithController:(AddContactViewController *) controller andIFContact:(IFContactModel *) contactModel {
        [self.contacts addObject:contactModel];

        // 保存通讯录数据
        [self cacheContacts];

        [self.tableView reloadData];
    }

    #pragma mark - EditContactDelegate
    - (void) editContactWithEditContactViewController:(EditContactViewController *) controller andContact:(IFContactModel *) contactModel {
        IFContactModel *con = self.contacts[self.tableView.indexPathForSelectedRow.row];
        con.username = contactModel.username;
        con.number = contactModel.number;
        [self.tableView reloadData];

        // 保存通讯录数据
        [self cacheContacts];
    }

    - (void)cacheContacts {
        // 保存通讯录数据
        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.contacts requiringSecureCoding:NO error:nil];
        BOOL result = [data writeToFile:kContactsPath atomically:YES]; // atomically缓存写入,避免文件损坏
        NSLog(@"%s , result = %d", __func__, result);
    }

@end



// AddContactViewController.h
#import <UIKit/UIKit.h>
#import "IFContactModel.h"
@class AddContactViewController;
@protocol AddContactDelegate <NSObject>
    @optional
    - (void) addContactWithController:(AddContactViewController *) controller andIFContact:(IFContactModel *) contactModel;
@end
@interface AddContactViewController : UIViewController
    @property (nullable, nonatomic, weak) id<AddContactDelegate> delegate;
@end

// AddContactViewController.m
#import "AddContactViewController.h"
@interface AddContactViewController ()
    @property (weak, nonatomic) IBOutlet UITextField *username;
    @property (weak, nonatomic) IBOutlet UITextField *number;
    @property (weak, nonatomic) IBOutlet UIButton *btnSave;
@end
@implementation AddContactViewController
    - (void)viewDidLoad {
        [super viewDidLoad];

        [self.username becomeFirstResponder];
    }

    - (IBAction)textChange:(UITextField *)sender {
        self.btnSave.hidden = (self.username.text.length > 0 && self.number.text.length > 0) ? NO : YES;
    }

    - (IBAction)saveContact:(UIButton *)sender {
        IFContactModel *con = [[IFContactModel alloc] init];
        con.username = self.username.text;
        con.number = self.number.text;

        [self.delegate addContactWithController:self andIFContact:con];
        [self.navigationController popViewControllerAnimated:YES];
    }
@end



// EditContactViewController.h
#import <UIKit/UIKit.h>
#import "IFContactModel.h"
@class EditContactViewController;
@protocol EditContactDelegate <NSObject>
    @optional
    - (void) editContactWithEditContactViewController:(EditContactViewController *) controller andContact:(IFContactModel *) contactModel;
@end
@interface EditContactViewController : UIViewController
    @property(nonatomic, strong) IFContactModel *contact;
    @property(nonatomic, weak) id<EditContactDelegate> delegate;
@end

// EditContactViewController.m
#import "EditContactViewController.h"
@interface EditContactViewController ()
    @property (weak, nonatomic) IBOutlet UIButton *btnSave;
    @property (weak, nonatomic) IBOutlet UITextField *username;
    @property (weak, nonatomic) IBOutlet UITextField *number;
@end
@implementation EditContactViewController
    - (void)viewDidLoad {
        [super viewDidLoad];

        self.username.text = self.contact.username;
        self.number.text = self.contact.number;
    }

    - (IBAction)editClick:(UIBarButtonItem *)sender {
        BOOL canEdit = !self.username.enabled;
        self.btnSave.hidden = !canEdit;
        self.username.enabled = canEdit;
        self.number.enabled = canEdit;
        [sender setTitle:canEdit ? @"取消" : @"编辑"];
        if (canEdit) {
            [self.number becomeFirstResponder];
        }
    }

    - (IBAction)saveContact:(id)sender {
        // 同一个对象, 这里修改对数据源生效
    //    self.contact.username = self.username.text;
    //    self.contact.number = self.number.text;

        // 通过代理传递参数
        IFContactModel * con = [[IFContactModel alloc] init];
        con.username = self.username.text;
        con.number = self.number.text;
        [self.delegate editContactWithEditContactViewController:self andContact:con];

        [self.navigationController popViewControllerAnimated:YES];
    }
@end

Copy the code

UIAlertController popup window

/ / UIAlertControllerStyleAlert bounced, UIAlertControllerStyleActionSheet playing at the bottom of the box UIAlertController * alert = [UIAlertController alertControllerWithTitle: @ "confirm cancellation?" Message: @ "after cancellation will return to the login" preferredStyle: UIAlertControllerStyleActionSheet]; / / 2. Create and add button UIAlertAction * okAction = [UIAlertAction actionWithTitle: @ "OK" style: UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"OK Action"); // alert }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { NSLog(@"Cancel Action"); }]; UIAlertAction *aAction = [UIAlertAction actionWithTitle:@"Aaaa" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { NSLog(@"Cancel Action"); }]; / / 2.1 add text boxes Only UIAlertControllerStyleAlert style can add input box / / [alert addTextFieldWithConfigurationHandler: ^ (UITextField at * _Nonnull textField) { // textField.placeholder = @"username"; //// [textField addTarget:self Action: @ the selector (alertUserAccountInfoDidChange forControlEvents) : UIControlEventEditingChanged]; / / to add respond to events / /}]; [alert addAction:okAction]; [alert addAction:cancelAction]; [alert addAction:aAction]; [self presentViewController:alert animated:YES completion:^{ }];Copy the code
UIAlertControllerStyleAlert style

UIAlertControllerStyleActionSheet style

PresentViewController opens a new page

#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super  viewDidLoad]; self.view.backgroundColor = [UIColor redColor]; } - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { UIViewController *vc = [[UIViewController alloc] init]; vc.view.backgroundColor = [UIColor blueColor]; / / set full screen switch page, the default UIModalPresentationAutomatic top transparent vc. ModalPresentationStyle = UIModalPresentationFullScreen; / / set the switch animation, the default from down to up vc. ModalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [Self presentViewController:vc Animated :YES completion:^{NSLog(@" Complete the jump ");}]; / / close the current ViewController / / [self dismissViewControllerAnimated: YES completion: ^ {/ / NSLog (@ "% s", __func__); / /}]. } @endCopy the code