0

UITableView の各 UITableViewCell に UIScrollView を追加しました。

これは私のコードです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* CellIdentifier = @"Cell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UIScrollView *propertyScrollView;
    if (cell == nil)
    {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        propertyScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tableView.frameWidth, 100)];
        [propertyScrollView setContentSize:CGSizeMake(10*tableView.frameWidth, 100)];
        [propertyScrollView setPagingEnabled:YES];
        propertyScrollView.delegate = self;
        propertyScrollView.tag = indexPath.row;
        [[cell contentView] addSubview:propertyScrollView];
        propertyScrollView.backgroundColor = [UIColor blackColor];
        int pagingIndex = [[m_pagingIndexArray objectAtIndex:indexPath.row]intValue];
        [propertyScrollView setContentOffset:CGPointMake(pagingIndex*propertyScrollView.frameWidth, 0)];
        for(int i=0;i<10;i++)
        {
            UIButton *singleImage =  [[UIButton alloc]initWithFrame:CGRectMake(i*tableView.frameWidth, 0, propertyScrollView.frameWidth, propertyScrollView.frameHeight)];
        [propertyScrollView addSubview:singleImage];
        singleImage.titleLabel.text = [NSString stringWithFormat:@"%d",i];
        singleImage.titleLabel.textColor = [UIColor blackColor];
        singleImage.titleLabel.font = systemFontBoldTypeOfSize(20);
        [singleImage setImage:[horizentalImagesArray objectAtIndex:i] forState:UIControlStateNormal];
        singleImage.backgroundColor = [UIColor whiteColor];
    }
    else
    {
        propertyScrollView.tag = indexPath.row;
        int pagingIndex = [[m_pagingIndexArray objectAtIndex:indexPath.row]intValue];
        [propertyScrollView setContentOffset:CGPointMake(pagingIndex*propertyScrollView.frameWidth, 0)];
    }
    return cell;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int pageIndex = scrollView.contentOffset.x/scrollView.frameWidth;
    [m_pagingIndexArray replaceObjectAtIndex:scrollView.tag withObject:[NSString stringWithFormat:@"%d",pageIndex]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    m_pagingIndexArray = [[NSMutableArray alloc]init];
    for(int i=0;i<10;i++)
    {
        [m_pagingIndexArray addObject:@"0"];
    }
}

1 つの UIScrollView (Paging Enabled) に 10 個の UIButton を追加しています。

問題は、UITableViewCell のスクロールビューのいずれかをスクロールして一番下のセルに移動すると、他の UITableViewCell のスクロールビューもそのコンテンツ オフセット ポイントまでスクロールされていることがわかります。

すべての UITableview セルの UIScrollView を個別にスクロールしたい。どうすれば達成できますか?この問題を解決するのを手伝ってください。

4

2 に答える 2