IOS之Block的应用-textFeild的回调应用
Block的一点优点为可以省略回调函数,简化代码今天我就应用了以下。
以下是代码片段。
_testTextField1=[[MyTextField alloc] init]; [self.view addSubview:_testTextField1]; [_testTextField1 release]; _testTextField1.obj=self; _testTextField1.textField.placeholder=@"小于5的字符判断"; _testTextField1.textField.font=[UIFont systemFontOfSize:14]; _testTextField1.myConditionBlock=^(NSString * str){//加入你要判断或者赋值的语句 if(str.length<=5) { return YES; } return NO;}; _testTextField1.myAlertBolck=^(id obj){ [_testTextField1.textField resignFirstResponder]; UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"test" message:@"请输入小于5的字符串" delegate:obj cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alertView show]; [alertView release ]; };
这样可以把判断条件和触发事件分开,并且放在一个实例里面。并且可以把两个实例相关联。使用起来较为方便。
以下是代码的下载地址:https://download.csdn.net/detail/matrixhero/4645105
最后更新:2017-04-02 15:15:05
上一篇:
黑客道德准则 不是所有的黑客都是罪犯
下一篇:
固态盘的集成与灾难恢复的维护
经过修改的读取配置文件PROPERTIES的小工具,对象尽量创建一次
天地超云发布“英雄战略” 瞄准中国云服务器第一
开发那点事系列二 - ClassLoader trouble shooting references
PagerSlidingTabStrip+换主题
Magento调试技巧之查看当前页面缓存过的block
android 短信字符转表情显示过程
DataBinder.Eval和Container.DataItem有什么区别
WebService——通过契约优先开发webservice
在 Docker 中运行 MySQL:多主机网络下 Docker Swarm 模式的容器管理
【重大漏洞预警】Windows两个关键远程代码执行漏洞