2

スクロールビューとページビューコントロールで設計されたカスタムセルがあり、次のように表示しています

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


static NSString * CellIdentifier = @"ScrollViewCell";
cell = (ScrollViewCell*)[newsTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    NSArray * customcellArray = [[NSBundle mainBundle]loadNibNamed:@"ScrollViewCell" owner:self options:nil];
    for(id customcellObject in customcellArray){
        if([customcellObject isKindOfClass: [UITableViewCell class]]){
            cell = (ScrollViewCell *)customcellObject;
            break;
        }
    }
}

// Customize your UIScrollView here..

[cell.scrollView setDelegate:self];
[cell.scrollView setPagingEnabled:YES];

scrollView = cell.scrollView;
pageControl = cell.pageControl;

cell.backgroundColor = [UIColor grayColor];

NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor],[UIColor blueColor], nil];
cell.scrollView.contentSize = CGSizeMake(cell.scrollView.frame.size.width * colors.count,cell.scrollView.frame.size.height);
for (int i = 0; i < colors.count; i++) {
    CGRect frame;
    frame.origin.x = cell.scrollView.frame.size.width * i;
    frame.origin.y = 0;
    frame.size = cell.scrollView.frame.size;

    UIView *subview = [[UIView alloc] initWithFrame:frame];
    subview.backgroundColor = [colors objectAtIndex:i];
    [cell.scrollView addSubview:subview];
}
// Configure the cell...
UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
bgview.opaque = YES;
bgview.backgroundColor = [UIColor grayColor];
[cell setBackgroundView:bgview];

return cell;
}

スクロールビューが表示され、セルでうまくスクロールしますが、問題はスクロールでページコントロールが更新されないことです。基本的に、スクロールビューのスクロールでページコントロールを更新したいのですが、ページコントロールとスクロールビューの両方がセルからのものであるため、達成する方法がわかりませんこれで、UIScrollViewDelegate プロトコルをセルで実装してから、テーブル ビューの親ビューを実装しようとしましたが、機能しませんでした。ガイドをお願いします。

ありがとうヴィシャル

4

1 に答える 1

3

UIPageControllカスタムセルにオーバーを配置しないでください。配置するUIScrollviewと、それ自体がスクロールされUIScrollViewます。したがって、このようにカスタムセルを作成し、各UIScrollview&UIPageControllのアウトレットを作成します。

カスタムセル

あなたの一つの変化cellForRowAtIndexPath

// Customize your UIScrollView here..

[cell.scrollView setDelegate:self];
[cell.scrollView setPagingEnabled:YES];
[cell.scrollView setTag:indexPath.row]; // set indexpath.row as tag for cell.scrollview

NSArray * colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor],[UIColor blueColor],nil];

cell.pageControll.numberOfPages = [colors count];

And in,

- (void)scrollViewDidScroll:(UIScrollView *)sender {

    CGFloat xOffset = sender.contentOffset.x;
    CGFloat frameWidth = sender.frame.size.width;

    int page = floor((xOffset - frameWidth / 2) / frameWidth) + 1;

    GroupButtonCell * cell = (GroupButtonCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag inSection:0]]; // get appropriate cell based on scrollview tag (sender.tag).
    cell.pageControll.currentPage = page; // assigning to pagecontroll

}

これが役立つことを願っています..

于 2013-04-10T04:20:59.103 に答える