2011-10-10 37 views
0

我在UITableView頁眉中添加了一個按鈕視圖。我已經正確設置了高度,並且當沒有顯示鍵盤時,按鈕實際上是功能性的。當按下一些文本字段(單元格中的UITextField)時,鍵盤將顯示,並且我已將表視圖框設置爲較小,因此可以單擊單元格,但問題在於按鈕 - 當按鈕與tableview中的某些字符相交時當按鈕沒有完全顯示時),該按鈕不起作用,並且當按鈕被完全顯示時該按鈕功能正常。在UITableView頁腳或頁眉中添加UIButton

我已經嘗試了將按鈕放在滾動視圖中,而不是放置在頁腳或tableview標題中,它完美地工作。這是一種UITableView頭錯誤?它可以修復嗎?

回答

0

添加下面的代碼:

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField 
{ 

     if(textField.tag != [[[yourTable indexPathsForVisibleRows] objectAtIndex:0]row]) 
      [self animateTextField: textField up: NO]; 
    return YES; 
} 

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 

    if(textField.tag != [[[yourTable indexPathsForVisibleRows] objectAtIndex:0]row]) 
    [self animateTextField: textField up: YES]; 
} 

- (void) animateTextField: (UITextField*) textField up: (BOOL) up 
{ 
    const int movementDistance = 300; // tweak as needed 
    const float movementDuration = 0.3f; // tweak as needed 

    int movement = (up ? -movementDistance : movementDistance); 

    [UIView beginAnimations: @"anim" context: nil]; 
    [UIView setAnimationBeginsFromCurrentState: YES]; 
    [UIView setAnimationDuration: movementDuration]; 
    self.view.frame = CGRectOffset(self.view.frame, 0, movement); 
    [UIView commitAnimations]; 
} 
+0

這是什麼碼?我應該在哪裏放?你能解釋爲什麼會發生這種情況嗎? – Lunayo

+0

此代碼用於在鍵盤按下文本框並出現鍵盤時調整視圖框架。把它放在你有問題的viewController中。 – Nitish