如何在TableView单元格中将scrollview连接到页面控件

我有一个自定义单元格设计与滚动视图和网页浏览控件,我显示如下

- (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协议,然后是表视图的父视图,但无法使其工作,请求指南。

谢谢Vishal

不要将UIPageControll放在UIScrollview的自定义单元格中,如果是,那么它将沿UIScrollView本身滚动。所以创建这样的自定义单元格并为每个UIScrollviewUIPageControll创建sockets,

定制单元格

您的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 } 

希望这会有所帮助..