2011-08-06 51 views
1

TableViewCell gets shifted up when keyboardIsShown爲什麼我的TableView會向上移動?

我有一個方法,當鍵盤顯示時被調用。它正在研究其他觀點。不知怎的,TableView會被移動。

-(void) keyboardDidShow:(NSNotification *) notification { 
// -- return if keyboard is still shown 
MyManager *sharedManager = [MyManager sharedManager]; 
if ([sharedManager.keyboardIsShown isEqualToString:@"YES"]) return; 
NSDictionary* info = [notification userInfo]; 

//---obtain the size of the keyboard--- 
NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey]; 
CGRect keyboardRect = [self.view convertRect:[aValue CGRectValue] fromView:nil]; 

//---resize the scroll view (with keyboard)--- 
CGRect viewFrame = [scrollView frame]; 
viewFrame.size.height -= keyboardRect.size.height; 
scrollView.frame = viewFrame; 

//---scroll to the current text field--- 
CGRect textFieldRect = [currentTextField frame]; 
[scrollView scrollRectToVisible:textFieldRect animated:YES]; 
sharedManager.keyboardIsShown = @"YES"; 

}

+0

您如何看待它? – Legolas

+0

你如何佈置你的觀點? – BoltClock

+1

你可以發佈你的'autoresizingmask'爲tableview嗎? –

回答

4

設置myTableView.autoresizingMask = 0;的伎倆。