How do I scroll a UITableView to a section that contains no rows?

后端 未结 6 714
盖世英雄少女心
盖世英雄少女心 2020-12-04 12:53

In an app I\'m working on, I have a plain style UITableView that can contain a section containing zero rows. I want to be able to scroll to this section using scrollToRowAtI

6条回答
  •  萌比男神i
    2020-12-04 13:09

    Since using:

    [NSIndexPath indexPathForRow:NSNotFound inSection:EXAMPLE]
    

    Broken for me in Xcode 11.3.1 (iOS simulator - 13.3) I decided to use:

    NSUInteger index = [self.sectionTypes indexOfObject:@(EXAMPLE)];
    if (index != NSNotFound) {
        CGRect rect = [self.tableView rectForSection:index];
        [self.tableView scrollRectToVisible:rect animated:YES];
    }
    

提交回复
热议问题