2012-02-28 52 views
0

在我的應用程序中,我有一個UITableView有一些自定義單元格,並在那些我已經放置UITextField。該UITextField有時會阻止我的鍵盤,這是一個問題。所以在我的情況下,我試圖移動整個tableview本身,而不是滾動到一個特定的單元格,這對我來說是一個問題。滾動UITableView框架問題,看單元格中的UITextField?

無論如何,我也有這樣的問題。

無論如何,這是我的代碼爲textField顯示方法和結束方法。問題是UITableView從不移動正確的數量。我只是試圖將UITableview移到足夠的位置,以便當前正在調用的UITextField的單元位於鍵盤之上。 所以有時候它滾動得太多,我看不到這個單元格,或者整個tableview在我看不到它的地方移動了一個瘋狂的數量。

無論如何,這裏是我的代碼,有沒有人看到任何錯誤?

- (BOOL)textFieldShouldBeginEditing:(UITextField *)thetextField { 
    CustomCell *cell = (CustomCell*)[[thetextField superview] superview]; 
    CGRect cellRect = [cell convertRect:cell.frame toView:self.view]; 
    float bottomCell = cellRect.origin.y - cellRect.size.height; 
    if (bottomCell >= keyboardY) { 
     subtractionAmount = keyboardY - bottomCell; 
     didMove = YES; 
     [UIView animateWithDuration:0.4 
         animations:^{ 
          thetableView.center = CGPointMake(thetableView.center.x, thetableView.center.y + subtractionAmount); 
         }]; 
    } 
    return YES; 
} 

-(BOOL) textFieldShouldReturn:(UITextField *)thetextField { 
    if (didMove) { 
     didMove = NO; 
     [UIView animateWithDuration:0.4 
         animations:^{ 
          thetableView.center = CGPointMake(thetableView.center.x, thetableView.center.y - subtractionAmount); 
         }]; 
    } 

謝謝!

回答

0

如果我不理會你的問題,我一個月前遇到了這個問題。我的方案如下:UITableViewUITextField s沒有UITableViewController

我修復了以下教程中的問題:sliding-uitextfields-around-to-avoid

希望它有幫助。

+0

從外觀來看,我正在做本教程中的所有內容,但有點不同,所以我仍然很好奇爲什麼上面的代碼不能完全工作。 – 2012-02-29 20:43:54