Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios IndExpathForVisibleRows包含不正确的行计数_Ios_Objective C_Iphone_Uitableview_Uiviewcontroller - Fatal编程技术网

Ios IndExpathForVisibleRows包含不正确的行计数

Ios IndExpathForVisibleRows包含不正确的行计数,ios,objective-c,iphone,uitableview,uiviewcontroller,Ios,Objective C,Iphone,Uitableview,Uiviewcontroller,我有一个带有tableView的viewController。在6s+上,5行是可见的,没有任何滚动。如果我点击一行并导航到下一个viewController,当我返回到我的tableView时,它的indExpathForVisibleRows是错误的 以下是我设置的测试代码: - (void)viewWillAppear:(BOOL)animated { ... NSLog(@"will appear: %@", self.tableView.indexPathsForVis

我有一个带有tableView的viewController。在6s+上,5行是可见的,没有任何滚动。如果我点击一行并导航到下一个viewController,当我返回到我的tableView时,它的
indExpathForVisibleRows
是错误的

以下是我设置的测试代码:

- (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}"
)
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}"
)
将显示:(空)
确实出现了:(
“{length=2,path=0-0}”,
“{length=2,path=0-1}”,
“{length=2,path=0-2}”,
“{length=2,path=0-3}”,
{length=2,path=0-4}
)
点击一行,然后返回带有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}"
)
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}"
)
将出现:(
“{length=2,path=0-0}”,
“{length=2,path=0-1}”,
“{length=2,path=0-2}”,
“{length=2,path=0-3}”,
“{length=2,path=0-4}”,

{length=2,path=0-5}方法
indexPathsForVisibleRows
返回表视图认为可见的单元格数。即使只有一行像素可见。此外,它可能会被剪裁,但如果它在内容区域内,表视图将对其进行计数。更重要的问题是,除了智力好奇之外,为什么要在意?方法
indexPathsForVisibleRows
返回表视图认为可见的单元格数。即使只有一行像素可见。此外,它可能会被剪裁,但如果在内容区域内,表视图将对其进行计数。更重要的问题是,除了好奇之外,为什么要在意?