zoukankan      html  css  js  c++  java
  • IOS之Block的应用-textFeild的回调应用

    Block的一点优点为可以省略回调函数,简化代码今天我就应用了以下。

    以下是代码片段。

    1. _testTextField1=[[MyTextField alloc] init];  
    2. [self.view addSubview:_testTextField1];  
    3. [_testTextField1 release];  
    4. _testTextField1.obj=self;  
    5. _testTextField1.textField.placeholder=@"小于5的字符判断";  
    6. _testTextField1.textField.font=[UIFont systemFontOfSize:14];  
    7. _testTextField1.myConditionBlock=^(NSString * str){//加入你要判断或者赋值的语句  
    8.     if(str.length<=5)  
    9.     {  
    10.       
    11.         return YES;  
    12.     }  
    13.     return NO;};  
    14. _testTextField1.myAlertBolck=^(id obj){  
    15.     [_testTextField1.textField resignFirstResponder];  
    16.     UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"test" message:@"请输入小于5的字符串" delegate:obj cancelButtonTitle:@"确定" otherButtonTitles: nil];  
    17.     [alertView show];  
    18.     [alertView release  ];  
    19. };  


    这样可以把判断条件和触发事件分开,并且放在一个实例里面。并且可以把两个实例相关联。使用起来较为方便。

    以下是代码的下载地址:http://download.csdn.net/detail/matrixhero/4645105

  • 相关阅读:
    NOIP2015 D1 解题报告
    2017.10.2 国庆清北 D2T2 树上抢男主
    2017.10.6 国庆清北 D6T3 字符串
    2017.10.1 国庆清北 D1T2 两个逗比捉迷藏
    电压驱动和电流驱动
    电子管
    点亮板载LED
    ESP8266——一般控制方法
    ESP8266——CPU频率更改和深度睡眠模式
    ESP8266——ADC
  • 原文地址:https://www.cnblogs.com/gaoxiao228/p/3190817.html
Copyright © 2011-2022 走看看