2016-05-14 6 views
0

私はUITextView(目的:コメント)を画面の下部に固定しています。ユーザーがコメントを追加したい場合は、キーボードが表示され、コメントの上にコメントがシフトします。キーボードを隠すためのキャンセルボタンもありますが、キーボードは隠されていません。キーボードがiosに隠されていない

//Set up NSNotification for Keyboard 
-(void) viewWillAppear:(BOOL)animated 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillToggle:) 
              name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillToggle:) 
              name:UIKeyboardWillHideNotification object:nil]; 
} 

//Code to shift comment view up with keyboard 
- (void) keyboardWillToggle:(NSNotification *)aNotification 
{ 
    CGRect frame = [self.navigationController.toolbar frame]; 
    CGRect keyboard = [[aNotification.userInfo valueForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue]; 
    frame.origin.y = keyboard.origin.y - frame.size.height; 
    [UIView animateWithDuration:[[aNotification.userInfo valueForKey:@"UIKeyboardAnimationDurationUserInfoKey"] floatValue] animations:^ 
    { 
    [self.navigationController.toolbar setFrame:frame]; 
}]; 
} 


//Hide keyboard 
-(void)cancelComment:(UIBarButtonItem*)sender{ 
    NSLog(@"cancelComment called"); 
    [self.view endEditing:YES]; 
} 

私はこれがうまくいくはずですか? "と呼ばれるcancelCommentは、" コンソールに記録されているが、キーボードが

+2

で[yourtextfield resignfirstresponder]これを追加考える

-(void)cancelComment:(UIBarButtonItem*)sender{ NSLog(@"cancelComment called”); [self.navigationController.view endEditing:YES]; } 

を試すことができます。 in cancelComment –

+1

それは、サブビューとしてテキストフィールドを持っているビューコントローラにありますか? – Wain

+0

ああそうだよ>。 abcf

答えて

2

SOLUTION隠されていません:あなたのcancelComment機能に

[yourtextfield resignfirstresponder]; 

あなたが置くことを忘れてしまったが。

0
- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    [yourtextfieldname resignfirstresponder]; 
} 

希望です!

1

あなたは私はあなたがself.viewでないのTextViewとself.navigationController.view

関連する問題