indexPathsForVisibleRows包含不正确的行计数

时间:2015-11-20 22:30:53

标签: ios objective-c iphone uitableview uiviewcontroller

我有一个带有tableView的viewController。在6s Plus上,可以看到5行而无需任何滚动。如果我点击一行并导航到下一个viewController,当我回到tableView时,它的indexPathsForVisibleRows是错误的。

这是我设置的测试代码:

- (void)viewWillAppear:(BOOL)animated
{
    ...
    NSLog(@"will appear: %@", self.tableView.indexPathsForVisibleRows);
}

- (void)viewDidAppear:(BOOL)animated
{
    ...
    NSLog(@"did appear: %@", self.tableView.indexPathsForVisibleRows);
}

当我第一次使用tableView进入viewController时,我得到了这个:

will appear: (null)
did appear: (
    "<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}",
    "<NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1}",
    "<NSIndexPath: 0xc000000000400016> {length = 2, path = 0 - 2}",
    "<NSIndexPath: 0xc000000000600016> {length = 2, path = 0 - 3}",
    "<NSIndexPath: 0xc000000000800016> {length = 2, path = 0 - 4}"
)

点击一行,然后使用tableView返回viewController,我得到了这个:

will appear: (
    "<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}",
    "<NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1}",
    "<NSIndexPath: 0xc000000000400016> {length = 2, path = 0 - 2}",
    "<NSIndexPath: 0xc000000000600016> {length = 2, path = 0 - 3}",
    "<NSIndexPath: 0xc000000000800016> {length = 2, path = 0 - 4}",
    "<NSIndexPath: 0xc000000000a00016> {length = 2, path = 0 - 5}"  <----THIS IS MY PROBLEM
)
did appear: (
    "<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}",
    "<NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1}",
    "<NSIndexPath: 0xc000000000400016> {length = 2, path = 0 - 2}",
    "<NSIndexPath: 0xc000000000600016> {length = 2, path = 0 - 3}",
    "<NSIndexPath: 0xc000000000800016> {length = 2, path = 0 - 4}"
)

为什么indexPathsForVisibleRows在导航后会在viewWillAppear中报告额外的可见行?

0 个答案:

没有答案