KeyListener in Objective-c
I'm new objective-c. I want to change button image if the textfields are filled. How do we understand a textfield input from the keyboard? KeyListener is using in java, how do we do in objective-c? Than开发者_如何学运维ks
Learn about notifications in Objective-C.
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html
If programming for iOS, then learn about UIControlEvents.
What you are looking for is a UITextFieldDelegate protocol. A protocol is roughly the same as an interface in Java. The main difference is that methods in protocols can be optional, whereas all methods in a Java interface is always required.
You could implement one or more of these methods:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// Do something when the user begins editing
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
// Do something when the user is done editing
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
// Text field is about to change it's text.
// Return YES to allow this change
// Return NO to block this change
}
Many classes in iOS have a corresponding delegate class. For example:
UITextField&UITextFieldDelegateNSXMLParser&NSXMLParserDelegateCLLocationManager&CLLocationManagerDelegate
So it is wise to look for the delegate counterpart in the documentation first when you want to listen to, or change the behavior of, an object instance.
加载中,请稍侯......
精彩评论