在我的应用程序中,我有一个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);
}];
}
谢谢!
从外观来看,我正在做本教程中的所有内容,但有点不同,所以我仍然很好奇为什么上面的代码不能完全工作。 – 2012-02-29 20:43:54