NSNotification在UITextField的应用
2016-05-02 12:00
393 查看
一 UITextField
NS_CLASS_AVAILABLE_IOS(2_0)
@interface UITextField :
UIControl <UITextInput,NSCoding>
@end
//UITextField的委托
@protocol UITextFieldDelegate <NSObject>
@optional
//委托实现的方法
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow
editing.
- (void)textFieldDidBeginEditing:(UITextField *)textField; // became first responder
- (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
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string; // return NO to not change text
- (BOOL)textFieldShouldClear:(UITextField *)textField; //
called when clear button pressed. return NO to ignore (no notifications)
- (BOOL)textFieldShouldReturn:(UITextField *)textField; //
called when 'return' key pressed. return NO to ignore.
@end
//UITextField通知
UIKIT_EXTERNNSString *const UITextFieldTextDidBeginEditingNotification;
UIKIT_EXTERNNSString *const UITextFieldTextDidEndEditingNotification;
UIKIT_EXTERN NSString *const UITextFieldTextDidChangeNotification;
二NSNotification
@interface NSNotification :NSObject <NSCopying,NSCoding>
@end
/**************** Notification Center****************/
@interface NSNotificationCenter :NSObject {
@package
void *__strong _impl;
void *__strong _callback;
void *_pad[11];
}
+ (NSNotificationCenter *)defaultCenter;
- (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullableNSString
*)aName object:(nullableid)anObject;
- (void)postNotification:(NSNotification *)notification;
- (void)postNotificationName:(NSString *)aName object:(nullableid)anObject;
- (void)postNotificationName:(NSString *)aName object:(nullableid)anObject
userInfo:(nullableNSDictionary *)aUserInfo;
- (void)removeObserver:(id)observer;
- (void)removeObserver:(id)observer name:(nullableNSString
*)aName object:(nullableid)anObject;
- (id <NSObject>)addObserverForName:(nullableNSString
*)name object:(nullableid)obj queue:(nullableNSOperationQueue
*)queue usingBlock:(void (^)(NSNotification *note))blockNS_AVAILABLE(10_6,
4_0);
// The return value is retained by the system, and should be held onto by the caller in
// order to remove the observer with removeObserver: later, to stop observation.
@end
三NSNotification在NSTextField中的使用
[[NSNotificationCenterdefaultCenter]
addObserverForName:UITextFieldTextDidBeginEditingNotification
object:nilqueue:nilusingBlock:^(NSNotification
*note) {
if (Self == note.object)
{
//do something }
}];
NS_CLASS_AVAILABLE_IOS(2_0)
@interface UITextField :
UIControl <UITextInput,NSCoding>
@end
//UITextField的委托
@protocol UITextFieldDelegate <NSObject>
@optional
//委托实现的方法
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow
editing.
- (void)textFieldDidBeginEditing:(UITextField *)textField; // became first responder
- (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
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string; // return NO to not change text
- (BOOL)textFieldShouldClear:(UITextField *)textField; //
called when clear button pressed. return NO to ignore (no notifications)
- (BOOL)textFieldShouldReturn:(UITextField *)textField; //
called when 'return' key pressed. return NO to ignore.
@end
//UITextField通知
UIKIT_EXTERNNSString *const UITextFieldTextDidBeginEditingNotification;
UIKIT_EXTERNNSString *const UITextFieldTextDidEndEditingNotification;
UIKIT_EXTERN NSString *const UITextFieldTextDidChangeNotification;
二NSNotification
@interface NSNotification :NSObject <NSCopying,NSCoding>
@end
/**************** Notification Center****************/
@interface NSNotificationCenter :NSObject {
@package
void *__strong _impl;
void *__strong _callback;
void *_pad[11];
}
+ (NSNotificationCenter *)defaultCenter;
- (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullableNSString
*)aName object:(nullableid)anObject;
- (void)postNotification:(NSNotification *)notification;
- (void)postNotificationName:(NSString *)aName object:(nullableid)anObject;
- (void)postNotificationName:(NSString *)aName object:(nullableid)anObject
userInfo:(nullableNSDictionary *)aUserInfo;
- (void)removeObserver:(id)observer;
- (void)removeObserver:(id)observer name:(nullableNSString
*)aName object:(nullableid)anObject;
- (id <NSObject>)addObserverForName:(nullableNSString
*)name object:(nullableid)obj queue:(nullableNSOperationQueue
*)queue usingBlock:(void (^)(NSNotification *note))blockNS_AVAILABLE(10_6,
4_0);
// The return value is retained by the system, and should be held onto by the caller in
// order to remove the observer with removeObserver: later, to stop observation.
@end
三NSNotification在NSTextField中的使用
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldTextDidChange) name:UITextFieldTextDidChangeNotification object:password];
[[NSNotificationCenterdefaultCenter]
addObserverForName:UITextFieldTextDidBeginEditingNotification
object:nilqueue:nilusingBlock:^(NSNotification
*note) {
if (Self == note.object)
{
//do something }
}];
相关文章推荐
- UItableview 添加 uisearchController
- [leetcode] 347. Top K Frequent Elements 解题报告
- Storyboard实现界面跳转
- Unique Paths II
- 纯java代码设置简单UI界面
- CoreThink主题开发(六)使用H-ui开发博客主题之首页友情链接标签混排
- UITableView基本介绍(一)
- Android_UI
- UIGestureRecognizer 手势浅析
- Unique Paths
- 1369 - Answering Queries<数>
- PS2游戏摇杆joystick与arduino uno简单实验
- XMG UITabBarController
- CoreThink主题开发(五)使用H-ui开发博客主题之首页显示站点公告
- UIAlertView和UIAlertController的使用
- C#OOP之十五 String类&StringBuilder类
- C#OOP之十五 String类&StringBuilder类
- C#OOP之十五 String类&StringBuilder类
- UIActivityIndicatorView官方文档及使用
- UIPageControl