Reputation: 1421
I am working on an social media type project and i am facing one serious problem.
This project is on iTunes from 2 years, so many user's data are already in server DB.
Now our client say's that each and every TextFiled's text's first letter must be capital.I can tackel the new user input with below line in UItextfiled category.
self.autocapitalizationType = UITextAutocapitalizationTypeWords;
but what about existing data?The data that I am showing in textfield when existing user will go for edit.
I have category applied in UItextField text for color and font consistancy but how can I override UItextFiled setter method?
Or suggest me any other way. Because there are more then hundred textfileds, how can i tackle with it? There are many classes rather then writing code for every class what will be the better solution?
I have writtern this code in UItextField+CustomText category.
- (void)setText:(NSString *)str {
//str= uppercase code
//self.text=str; //this is recursive fn call
}
This setter is called every time when i am assigning any text to any textfield (textfield.text) but how to that modified str assign again to that specific textfield.
Upvotes: 2
Views: 1314
Reputation: 1530
Just call the super's methods in your overrides:
- (NSString *)text
{
// do your extra stuff here
// ...
return [super text];
}
- (void)setText:(NSString *)text
{
[super setText:text];
// do your extra stuff here
// ...
}
Upvotes: 1
Reputation: 121
You need to set iVar directly when using custom setter. Other wise it will be recursive infinite stack same as your code. Following should be fine in your case
- (void)setText:(NSString *)str {
strUpperCase= uppercase code
_str = strUpperCase;// or str = strUpperCase; // One of this
}
Upvotes: 1
Reputation: 597
Maybe you can use target to change:
[textField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
better will be set in textfield autocapitalizationType
self.textfield.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
Upvotes: 1
Reputation: 5592
You need to Modify the text by this method by updating str value than:
Simply Call this method:
[self setText:@"ENTER TEXT"];
What it does is it will call the method & str will be updated with new string & that will be assigned again to textField
.
I hope this is what you are looking for.
Upvotes: 0