简体   繁体   English

如何在UITableView上滚动

[英]How to scroll on UITableView

I have a UITableView that I want to scroll to the next row from the top (such as the 3rd row, then the 4th row, etc...). 我有一个UITableView,我想从顶部滚动到下一行(例如第三行,然后是第四行,等等)。 Is there an easy way to determine which rows in a table are being displayed? 有没有一种简单的方法来确定要显示表中的哪些行?

It seems like I will have to call indexPathsForVisibleRows and do a bunch of manipulation to figure out which rows are being displayed (and whether I am at the bottom of my table) 看来我将不得不调用indexPathsForVisibleRows并进行大量操作以弄清楚正在显示的行(以及是否位于表的底部)

Thanks, 谢谢,

Nate 内特

I assume you are talking about each cell having some kind of text input, where you enter some data, then you want to go to the next cell and enter some data there; 我假设您正在谈论的是每个具有某种文本输入的单元格,在其中输入一些数据,然后您要转到下一个单元格并在其中输入一些数据。 so that's how I'm going to answer. 所以这就是我要回答的方式。

Generally what I do, is in my viewWillAppear: i put somewhere, [[cell textField] becomeFirstResponder]; 通常,我所做的是在viewWillAppear中:我放在某个地方,[[单元格textField]成为FirstResponder]; to ensure that the user doesn't have to tap on the first item, the keyboard just pops up and they can type. 为了确保用户不必点击第一项,只需弹出键盘即可输入。 Conversely, I put [[cell textField] resignFirstResponder]; 相反,我把[[cell textField] resignFirstResponder]; inside a loop after checking if that cell is the first responder, in my viewWillDisappear:. 在我的viewWillDisappear:中检查该单元格是否是第一个响应者后,在循环内进行。

Now, here's the part you probably don't know. 现在,这是您可能不知道的部分。 I implement the optional UITextFieldDelegate method textFieldShouldReturn: something like this: 我实现了可选的UITextFieldDelegate方法textFieldShouldReturn:类似这样:

- (BOOL)textFieldShouldReturn:(UITextField*)textField
{
    if([textField returnKeyType] != UIReturnKeyDone)
    {
        UIView* nextTextField = [[self tableView] viewWithTag:[textField tag] + 1];
        [nextTextField becomeFirstResponder];
    }
    else
        // Do something else, like pop a view controller
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM