[IOS] Detect UITextField status, focus

Ideas:

Use UITextFieldDelegate:

UITextFieldTextDidBeginEditingNotification;开始编辑时
UITextFieldTextDidEndEditingNotification;结束编辑时
UITextFieldTextDidChangeNotification;值改变时

 

Register a notification to listen for UITextField events

-(void)viewWillAppear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeAllDropDownTable) name:UITextFieldTextDidBeginEditingNotification object:nil];
}

 

Business method:

-(void)closeAllDropDownTable{
    if (_encrypt_dropDownMenuTable.isOpen) {
        [_encrypt_dropDownMenuTable.view removeFromSuperview];
    }
    if (_channel_dropDownMenuTable.isOpen){
        [_channel_dropDownMenuTable.view removeFromSuperview];
    }
}

 

Takedown notice:

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    // remove notification center
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidBeginEditingNotification object:nil];
    
}

 In this way, the business method can be called as soon as the textfield gets the focus.

 

refer to:

1.http://www.jianshu.com/p/0ab41087cf32

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326070344&siteId=291194637