2014-05-22 2 views
1

나는 여전히 객관적인 밧줄을 배우고 있으므로 나와 함께하시기 바랍니다.숨겨진 버튼 표시

현재 버튼을 누르면 iOS 키보드가 숨겨집니다. 나는 내가 어떻게 이것의 반대를 할 수 있는지 궁금해하고 있었다. 텍스트 필드가 선택되면 키보드가 자동으로 나타납니다. 동시에이 버튼을 화면에 표시하고 싶습니다.

감사합니다. 이 같은 UIKeyboardWillShowNotification에 대한

-(IBAction)done:(id)sender{ 
//... 
//... 
[Screen resignFirstResponder]; 
done.hidden = YES; 
}; 

답변

0

NSNotification을 사용해야합니다. addObserver viewWillDisappear에서 viewWillAppearremoveObserver에서

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

-(void)viewWillDisappear:(BOOL)animated{ 
    [super viewWillDisappear:animated]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; 
} 

-(void)keyboardWillShow:(NSNotification*)notification{ 
    done.hidden = NO; 
} 
0

레지스터 :

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 

및 제공 방법에있는 버튼을 보여

-(void) keyboardWillShow:(NSNotification*)notification{ 
    done.hidden = NO; 
} 

가와의 dealloc에서 관찰자를 제거하는 것을 잊지 마세요

[[NSNotificationCenter defaultCenter] removeObserver:self]; 
+0

dealloc에서 관찰자를 제거하십시오. – Logan

+0

물론 - 고마워요! 나는 이것을 포함하도록 나의 대답을 업데이트 할 것이다, 나는 그것이 분명하다고 생각했다;) – robert

+0

그래, 아마 그럴거야.하지만 초보자가이 대답에 걸려 넘어지면, 나는 그것을 포함시키는 것이 유용 할거라고 생각했다. :) – Logan

0

당신은 예를 들어,이를 달성하기 위해 UITextFieldDelegate 방법을 사용할 수 있습니다 구현 :

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    done.hidden = NO;  
    return YES; 
} 

그것이 도움이되기를 바랍니다.