简体   繁体   中英

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...). 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)

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]; 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]; inside a loop after checking if that cell is the first responder, in my viewWillDisappear:.

Now, here's the part you probably don't know. I implement the optional UITextFieldDelegate method textFieldShouldReturn: something like this:

- (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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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