Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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:如何判断是否在UITableView中滚动通过某一行?_Ios_Objective C_Uitableview - Fatal编程技术网

iOS:如何判断是否在UITableView中滚动通过某一行?

iOS:如何判断是否在UITableView中滚动通过某一行?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我需要一种方法来检测我是否在UITableView中滚动过第5行。一旦我通过第五行,我想调用一个方法。我不知道怎么做,也不知道从哪里开始。我将发布UITableView代码。如果有人能帮助我,我将不胜感激 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ListingCell *cell ; if (cell == nil) {

我需要一种方法来检测我是否在UITableView中滚动过第5行。一旦我通过第五行,我想调用一个方法。我不知道怎么做,也不知道从哪里开始。我将发布UITableView代码。如果有人能帮助我,我将不胜感激

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
   {
ListingCell  *cell ;
if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ListingCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 100;
}

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 20;
}

您所要做的就是实现UIScrollViewDelegate方法
-scrollViewDidScroll
。然后,您可以从当前UITableView
contentOffset
属性中手动计算所需的任何内容

-(void)scrollViewDidScroll:(UIScrollView *)inScrollView
{
    int currentOffsetY = inScrollView.contentOffset.y;

    //Now use that y position to figure out if you have scrolled past where you want.
}

您可能还需要一个布尔值,因此只需调用“pass here”方法一次。

您所要做的就是实现UIScrollViewDelegate方法
-scrollViewDidScroll
。然后,您可以从当前UITableView
contentOffset
属性中手动计算所需的任何内容

-(void)scrollViewDidScroll:(UIScrollView *)inScrollView
{
    int currentOffsetY = inScrollView.contentOffset.y;

    //Now use that y position to figure out if you have scrolled past where you want.
}
您可能还需要布尔值,因此只需调用“pass here”方法一次。

请尝试以下操作:

- (void)scrollViewDidScroll:(UITableView *)tableView
{
    CGRect row = [tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:0];
    if (tableView.contentOffset.y > CGRectGetMaxY(row)) {
        // you did it
    }
}
CGRectGetMinY
,具体取决于您想要实现的目标。

请尝试以下操作:

- (void)scrollViewDidScroll:(UITableView *)tableView
{
    CGRect row = [tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:0];
    if (tableView.contentOffset.y > CGRectGetMaxY(row)) {
        // you did it
    }
}

CGRectGetMinY
,具体取决于您试图实现的目标。

如果您的所有行的高度都相同,则实现下面Putz1103的答案应该足够简单。如果您的所有行的高度都相同,则实现下面Putz1103的答案应该足够简单。