IOS开发之协议 代理

回顾:
 1、协议
 2、代理
 3、程序的执行流程
 
 1、协议:公共接口 可以在协议里面声明 一些公共的方法 只要遵守协议的类  都可以使用这些协议方法
 导入协议:<协议名>
 好处:节省代码量  不用重复去声明相同的方法
 
 2、代理:委托别人去帮忙做某件事 也是一个特殊的协议
 
 3、程序的执行流程
 程序的入口是main 
 main会根据程序的运行状态   使用代理  去调用  对应状态的方法
 
 启动流程:
 1、main程序的入口
 main
 2、加载完所有选项 准备启动 -> 可以在这个方法里面写 需要加载的内容(窗口、启动时需要创建的对象、数据)(只执行一次)
 application:didFinishLaunchingWithOptions:
 3、进入活动状态-》可以看到加载出来的内容 -》还原之前的状态(不止调用一次)
 applicationDidBecomeActive:
 
 
 按HOME键或者其他使应用程序进入后台步骤:
 1、即将进入非活动状态(不止调用一次)->想要保存的应用状态
 applicationWillResignActive:
 2、进入后台状态(之前进入后台15秒后应用程序将不再运行)如果想让程序一直运行  可以在这个方法里面进行操作 (不止调用一次)
 applicationDidEnterBackground:
 
 
 再次回到应用程序执行流程:
 1、即将回到前台(不止调用一次)
 applicationWillEnterForeground:
 2、已经进入活动状态
 applicationDidBecomeActive:
 
 
 即将退出应用程序(只调用一次)
 applicationWillTerminate:
 
 
 
/*
 UITextField:->UIControl的子类->UIView的子类
 enabled  tag - (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
 
 文本输入框
 text:可以获得 或者改变  输入框的文字内容
 placeholder:提示文字
 textColor:字体颜色
 font:字号
 textAlignment:对齐方式
 adjustsFontSizeToFitWidth:让文字自动根据宽度适配
 minimumFontSize:设置 文字的最小字号
 ✮✮✮✮✮delegate:代理  
 clearButtonMode:设置清除按钮 什么时候显示
 UITextFieldViewModeNever,//永远不显示
 UITextFieldViewModeWhileEditing,//当编辑的时候显示
 UITextFieldViewModeUnlessEditing,//不再编辑的时候显示
 UITextFieldViewModeAlways//永远显示
 
 
 leftView:左侧视图->输入框左侧视图
 rightView:右侧视图->输入框右侧视图
 ✮✮✮✮✮并不是设置了 左侧右侧视图  就可以显示出来  需要配合使用下面属性
 leftViewMode:设置 什么情况下 显示左侧视图
 rightViewMode:设置 什么情况下 显示右侧视图
 
 inputView:键盘上面的视图
 inputAccessoryView:键盘区域的视图
 
 borderStyle:输入框的样式
 UITextBorderStyleNone,没有样式
 UITextBorderStyleLine,黑线边框
 UITextBorderStyleBezel,黑线阴影
 UITextBorderStyleRoundedRect圆角
 
 keyboardType:键盘的样式
 UIKeyboardTypeDefault,                // Default type for the current input method.
 UIKeyboardTypeASCIICapable,           // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
 
 ✮✮✮✮✮数字符号
 UIKeyboardTypeNumbersAndPunctuation,  // Numbers and assorted punctuation.
 
// URL类型
 UIKeyboardTypeURL,                    // A type optimized for URL entry (shows . / .com prominently).
 
 ipad 只显示数字(0-9)
 UIKeyboardTypeNumberPad,              // A number pad (0-9). Suitable for PIN entry.
 
// 电话类型(1-9, *, 0, #)
 UIKeyboardTypePhonePad,               // A phone pad (1-9, *, 0, #, with letters under the numbers).
 UIKeyboardTypeNamePhonePad,           // A type optimized for entering a person's name or phone number.
 
 邮箱地址
 UIKeyboardTypeEmailAddress,           // A type optimized for multiple email address entry (shows space @ . prominently).
 UIKeyboardTypeDecimalPad NS_ENUM_AVAILABLE_IOS(4_1),   // A number pad with a decimal point.
 UIKeyboardTypeTwitter NS_ENUM_AVAILABLE_IOS(5_0),      // A type optimized for twitter text entry (easy access to @ #)
 
 网页搜索 有小地球
 UIKeyboardTypeWebSearch NS_ENUM_AVAILABLE_IOS(7_0),    // A default keyboard type with URL-oriented addition (shows space . prominently).
 
 UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
 
 
 输入框的方法(代理方法)
 
 开始编辑的调用
 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
 - (void)textFieldDidBeginEditing:(UITextField *)textField;
 
 
 结束编辑的时候调用
 - (BOOL)textFieldShouldEndEditing:(UITextField *)textField;
 - (void)textFieldDidEndEditing:(UITextField *)textField;
 
 文字内容改变的时候调用
 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
 
 
 点击清除按钮的时候 调用
 - (BOOL)textFieldShouldClear:(UITextField *)textField;  
 
 点击Return键的时候调用
 - (BOOL)textFieldShouldReturn:(UITextField *)textField;
 
 
 UIControlEventEditingDidBegin                                   = 1 << 16,     // UITextField
 UIControlEventEditingChanged                                    = 1 << 17,
 UIControlEventEditingDidEnd                                     = 1 << 18,
 UIControlEventEditingDidEndOnExit                               = 1 << 19,     // 'return key' ending editing
 
 专为输入框准备的响应事件
 
 
 注意点:
 1、如果想使用代理方法  必须先导入代理
 2、如果代理方法 没有触发  看是否 挂上了代理
 
 在使用左右侧视图的时候  要配合左右侧视图的model来使用
 
 
 
 
 作业:
 1、写三个工程 
 (1)登录(使用OC时候写的逻辑)
 (2)注册(使用OC时候写的逻辑)
 (3)修改密码(使用OC时候写的逻辑)
 
 2、每个人项目的需求文档、流程图
 
 
 
原文地址:https://www.cnblogs.com/Biaoac/p/5025227.html