首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

UITextField署理详解

2013-09-15 
UITextField代理详解第一继承自UIControl添加事件[textFieldaddTarget:selfaction:@selector(didDone:)for

UITextField代理详解

第一继承自UIControl

添加事件

    [textFieldaddTarget:selfaction:@selector(didDone:)forControlEvents:UIControlEventEditingDidEndOnExit];

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;       // return NO to disallow editing.

返回值是true或false

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

{

   NSLog(@"textFieldShouldBeginEditing");

   return YES;

}

- (void)textFieldDidBeginEdiUITextField *)textField;          // became first responder

此时已变成第一响应者

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField

{

    NSLog(@"textFieldDidBeginEditing");

    return YES;

}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;         // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end

编辑完之后,键盘放弃第一响应者


- (void)textFieldDidEndEditing:(UITextField *)textField;            // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called

输入结束之后调用

- (void)textFieldDidEndEditing:(UITextField *)textField

{

  NSLog(@"textFieldDidEndEditing");

}


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;   // return NO to not change text

通过每次输入的内容,返回YES,则会在textField做显示,否则不显示

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

{

    NSLog(@"the input char is %@",string);

    return YES;

}


- (BOOL)textFieldShouldClear:(UITextField *)textField;              // called when clear button pressed. return NO to ignore (no notifications)

 如果返回值是NO ,则点击clear不会清除

- (BOOL)textFieldShouldClear:(UITextField *)textField

{

    NSLog(@"textFieldShouldClear");

    return NO;

}


- (BOOL)textFieldShouldReturn:(UITextField *)textField;             // called when 'return' key pressed. return NO to ignore

点击return 钮之后,是否仍然显示

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{// called when 'return' key pressed. return NO to ignore.

    return NO;

}


热点排行