Reputation: 441
Hi and thanks in advance for any responses.
I'm working with two UIViews with the Ipad. If the user makes changes to the text field in one view, I want those changes to appear in the textfield of the other view. I have one text field in each view. In IB, I gave them the same tag and textfield delegate. I only have one IBOutlet but I dont think it possible to connect to both text field? I tried IBOutletCollection but it doesn't support textfields. I don't know where to go from here?What should I do? Any advice is appreciated!thanks!
Upvotes: 0
Views: 570
Reputation: 47241
The answer is bindings an KVO(Key-Value-Observation). The idea behind this is: One object observes changes of another object's property.
Have a look at KVO and Bindings on iPhone on Mindsizzlers.com or take a look at the book Cocoa Design Patterns Chapter 32 Bindings and Controllers.
Upvotes: 1
Reputation: 18670
You can use the UITextField delegate methods to detect text changes in one text field and update the other. The method below gets called every time a character is typed in one of the textfields (provided you have set your view controller to be the UITextField delegate):
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
// Here you can run your logic to detect which textField has changed (using tags)
// And update them accordingly.
}
Upvotes: 0