选择文本字段时使 UITableView 滚动

Making a UITableView scroll when text field is selected(选择文本字段时使 UITableView 滚动)
本文介绍了选择文本字段时使 UITableView 滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量的反复试验,我放弃并提出这个问题.我见过很多人有类似的问题,但无法得到所有正确的答案.

After a lot of trial and error, I'm giving up and asking the question. I've seen a lot of people with similar problems but can't get all the answers to work right.

我有一个由自定义单元格组成的 UITableView.单元格由 5 个彼此相邻的文本字段组成(有点像网格).

I have a UITableView which is composed of custom cells. The cells are made of 5 text fields next to each other (sort of like a grid).

当我尝试滚动和编辑 UITableView 底部的单元格时,我无法将单元格正确定位在键盘上方.

When I try to scroll and edit the cells at the bottom of the UITableView, I can't manage to get my cells properly positioned above the keyboard.

我已经看到很多关于更改视图大小等的答案......但到目前为止,它们都没有很好地工作.

I have seen many answers talking about changing view sizes,etc... but none of them has worked nicely so far.

谁能用一个具体的代码示例阐明正确"的做法?

Could anybody clarify the "right" way to do this with a concrete code example?

推荐答案

滚动的功能可以简单得多:

The function that does the scrolling could be much simpler:

- (void) textFieldDidBeginEditing:(UITextField *)textField {
    UITableViewCell *cell;

    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
    // Load resources for iOS 6.1 or earlier
        cell = (UITableViewCell *) textField.superview.superview;

    } else {
        // Load resources for iOS 7 or later
        cell = (UITableViewCell *) textField.superview.superview.superview; 
       // TextField -> UITableVieCellContentView -> (in iOS 7!)ScrollView -> Cell!
    }
    [tView scrollToRowAtIndexPath:[tView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

就是这样.根本没有计算.

That's it. No calculations at all.

这篇关于选择文本字段时使 UITableView 滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)