here is the problem, when I debug my program, I found that the keyboardWillShow function does not respond every time. for the first time it will be called by the program. here is my code, I donβt know what is wrong in my code, but when the keyboard first appeared, the function works well.
- (void)keyboardWillShow:(NSNotification *)notification { NSDictionary *userInfo = [notification userInfo];
and I register a notice
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; }
and delete it here
- (void)viewDidUnload { [super viewDidUnload]; [self save]; self.textview = nil; self.title = nil; self.tags = nil; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; }
i resigns firstresponder, here is my code
- (IBAction)save:(id)sender { self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNote)] autorelease]; [textview resignFirstResponder]; } - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(save:)] autorelease]; [self setUpUndoManager]; return YES; } - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{ [self save]; return YES; }
source share