在iOS中滚动UITableView时尝试使用VisibleCell

在iOS中滚动UITableView时尝试使用VisibleCell,ios,uitableview,uiimageview,Ios,Uitableview,Uiimageview,我正在构建一个应用程序,其中UIImageView以编程方式遍历UITableView。我创建了两个按钮(“向上”和“向下”),控制UIImageView移动的方向。如果UIImageView正在向上/向下移动到当前不可见的行,我尝试通过编程方式滚动UITableView。我意识到我需要使用UITableView方法“visibleCells”来检查是否返回数组中的单元格。如果单元格不在数组中,那么我需要将表格向上/向下精确滚动一行(每次用户单击“向上”/“向下”按钮时)。不幸的是,我没有遇到任

我正在构建一个应用程序,其中UIImageView以编程方式遍历UITableView。我创建了两个按钮(“向上”和“向下”),控制UIImageView移动的方向。如果UIImageView正在向上/向下移动到当前不可见的行,我尝试通过编程方式滚动UITableView。我意识到我需要使用UITableView方法“visibleCells”来检查是否返回数组中的单元格。如果单元格不在数组中,那么我需要将表格向上/向下精确滚动一行(每次用户单击“向上”/“向下”按钮时)。不幸的是,我没有遇到任何关于如何使用该方法的好例子,我需要帮助。这是我这里的代码:

- (IBAction)buttonClicked:(id)sender {

    if([sender tag] == 1){

        //here is where I will need to make the call to [_tableView visibleCells] to see if the cell that the UIImageView is about to scroll up to is within this array.  If not, then programmatically scroll up one row.
        if (_index.row == 0) {

            _index = [NSIndexPath indexPathForRow:[_tableData count] - 1 inSection:_index.section];
            [_table scrollToRowAtIndexPath:_index atScrollPosition:UITableViewScrollPositionTop animated:YES];

        }

        else
            _index = [NSIndexPath indexPathForRow:_index.row - 1 inSection:_index.section];

        [UIView animateWithDuration:.3 animations:^{
            CGRect rect = [self.view convertRect:[_table rectForRowAtIndexPath:_index] fromView:_table];

            CGFloat floatx = _imageView.frame.origin.x - rect.origin.x;
            _imageView.frame = CGRectMake(rect.origin.x + floatx, rect.origin.y, _imageView.frame.size.width, _imageView.frame.size.height);
        }];

    }

    else if([sender tag] == 2){


         if (_index.row + 1 == [_tableData count]) {

            _index = [NSIndexPath indexPathForRow:0 inSection:_index.section];
            [_table scrollToRowAtIndexPath:_index atScrollPosition:UITableViewScrollPositionBottom animated:YES];

        }

         else
             _index = [NSIndexPath indexPathForRow:_index.row + 1 inSection:_index.section];

        [UIView animateWithDuration:.3 animations:^{
            CGRect rect = [self.view convertRect:[_table rectForRowAtIndexPath:_index] fromView:_table];

            CGFloat floatx = _imageView.frame.origin.x - rect.origin.x;
            _imageView.frame = CGRectMake(rect.origin.x + floatx, rect.origin.y, _imageView.frame.size.width, _imageView.frame.size.height);
        }];

    }

}

有人能告诉我如何实现我想要实现的功能吗?

如果您有一点时间学习一些新东西,我建议您尝试一下。您可以使用垂直iCarousel来实现以下目标:

它类似于UITableView,但是对于旋转木马中的每个项目,您可以设置任何UIView,然后您可以显示设置
currentItemIndex
属性的特定项目


看看是否适合你。伊卡鲁塞尔救了我两天的工作

我不确定这是否是我正在寻找的东西,但谢谢分享。