2010-12-15 92 views
2

我想實現代碼,以推動向上滾動,如果隱藏在鍵盤下。 代碼中的第一部分,它說:「在你的視圖控制器的某處調用此方法」應該在視圖中加載的地方在哪裏?我應該寫 [self.registerForKeyboardNotifications}; ??請幫忙。我應該在視圖控制器中調用方法?

// Call this method somewhere in your view controller setup code. 
- (void)registerForKeyboardNotifications 
{ 
[[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(keyboardWasShown:) 
     name:UIKeyboardDidShowNotification object:nil]; 

[[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(keyboardWillBeHidden:) 
     name:UIKeyboardWillHideNotification object:nil]; 

} 

回答

2

一個地方,你可以稱之爲viewWillAppear。 您要使用的線

[self registerForKeyboardNotifications]; 

確保在視線中消失,你從通知中心刪除自己以及。

+0

並刪除我簡單寫入:registerForKeyboardNotifications =零; 對不對? – Shinnawy 2010-12-16 00:11:45

+0

你可能想要寫一個resignFromKeyboardNotifications方法,並在該調用中[[NSNotificationCenter defaultCenter] removeObserver:self name:*將通知名稱放在這裏* object:nil] – MCannon 2010-12-16 00:18:36

相關問題