1

UIViewControllerにUITableViewがあります。そして、この表には、5つの表示可能なカテゴリから選択する「言う」があります。しかし、コンテンツを保持する配列には、「言う」10のカテゴリがあります。私が今作成したのは、インデックス0のカテゴリ1からインデックス9のカテゴリ10に移動する通常のスクロールテーブルです。しかし、私が欲しいのは、カテゴリ10の後のカテゴリ1とその逆です。

つまり、基本的には静的配列の無限ループです。

私はscrollViewDidScroll:メソッドでこれを試しましたが、そうすると、UITableViewがスクロールするのと同じようにスクロールしません。ランダムな場所にRACESし、1つまたは2つのカテゴリを移動することは不可能です。

これが私のコードのサンプルです。誰かが助けてくれることを願っています。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == categoryView){
        if (categoryView.contentOffset.y > 0.0) {
            loopcounter++;
            NSLog(@"ScrollView Scrolled DOWN");
            [categorytablecontent insertObject:[categorytablecontent objectAtIndex:0] atIndex:[categorytablecontent count]-1];
            [categorytablecontent removeObjectAtIndex:0];
            [categoryView reloadData];
        }
        if (categoryView.contentOffset.y < 0.0) {
            loopcounter = [categorytablecontent count];
            NSLog(@"ScrollView Scrolled UP");
            [categorytablecontent insertObject:[categorytablecontent objectAtIndex:[categorytablecontent count]-1] atIndex:0];
            [categorytablecontent removeObjectAtIndex:[categorytablecontent count]-1];
            [categoryView reloadData];
        }

        a = categoryView.visibleCells;

        for (UITableViewCell *cell in a){
            NSLog(@"Current Visible cell: %@", cell.textLabel.text);
        }
        NSLog(@"Current offset: %@", categoryView.contentOffset.y);
    }
}
4

1 に答える 1

2

これを行うには、1 つ以上の良い方法があります。UITableViewDataSourceコントローラはProtocolを実装していますか? その場合、おそらく最も簡単な方法は、データセット サイズのモジュロを で返すことcellForRowAtIndexPathです。

何かのようなもの:

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    // Use appropriate fields for your categorytablecontent object here...
    cell.textLabel.text = [categorytablecontent objectAtIndex:(indexPath.row % [categorytablecontent count])];

    return cell;
}

これにより、静的 (または動的) コンテンツをループするスムーズな無限スクロールが実現します。

于 2012-06-14T16:03:39.580 に答える