iphone: uitextfield, multiple textfields with the same delegate?

核能气质少年 提交于 2019-12-01 17:36:57

Set a tag on the textfield on initialization, then check the UITextField object that is passed into the delegate method's tag, then you'll be able to make a differentiation between the two textfields:

#define FIELD_ONE_TAG 1
#define FIELD_TWO_TAG 2

UITextField *textFieldOne = ...
textFieldOne.tag = FIELD_ONE_TAG;
...
UITextField *textFieldTwo = ...
textFieldTwo.tag = FIELD_TWO_TAG;


- (void)textFieldDidBeginEditing:(UITextField *)textField {
   if(textField.tag == FIELD_ONE_TAG) { //field one
   } else {//field two

   }
}
UITextField *textFieldOne=..... 

UITextField *textFieldTwo=....
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField == textFieldOne)
{ // field one code
}else{
//field two code
}
}

have two references of the inserted text views and u can compare them at the delegate methods. Not much needed with tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!