ios 监听注册通知 移除通知

 //通知
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    //注册通知
    [center addObserver:self selector:@selector(textValueChanged:) name:UITextFieldTextDidChangeNotification object:_textf];
#pragma mark 监听文本框内容
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    _str = [NSMutableString stringWithString:textField.text];
    [_str replaceCharactersInRange:range withString:string];
    NSLog(@"%@",_str);
    _st=[NSMutableString stringWithFormat:@"%@.00",self.str];
    
    
    
    
    return YES;
}


///监听文本框的值的改变
- (void)textValueChanged:(NSNotification *)notice
{
    if([_textf.text isEqual: @""] ){
        _btn.enabled = NO;
        
        
    }else{
//        _btn.enabled=NO;
   
    }
}
//移除通知
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

版权声明:本文为qq_43361450原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。