【问题标题】:Scrolling horizantal on UITableView is changing the position of the UIPageControl which is attached to a scrollView inside the TableView cellUITableView 上的水平滚动正在改变 UIPageControl 的位置,该 UIPageControl 附加到 TableView 单元格内的滚动视图
【发布时间】:2014-06-18 14:03:35
【问题描述】:

我有一个带有动态生成的自定义单元格的 tableView,其中一个自定义单元格包含一个可以垂直滚动的 scrollView,并且附加了一个页面控件。

tableview的用户界面结构见照片。

我在scrollViewDidScroll方法中刷新页面控件的位置如下。

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

    NSIndexPath *indexPathPageControl=[NSIndexPath indexPathForRow:0 inSection:0];
    UITableViewCell * cell = (UITableViewCell*)[self.sonDakikaTableView cellForRowAtIndexPath:indexPathPageControl];


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



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

    UIPageControl *pageControl = (UIPageControl *)[cell.contentView  viewWithTag:14];
    pageControl.currentPage = page; // assigning to pagecontroll


}

当用户在 scrollView 中垂直滚动时,它工作得很好。

但是,当用户在 tableView 上向下滚动并且垂直 scrollView 的单元格不再可见时,整数页面变量正在更新为 0,并且当用户向上滚动并且表格视图单元格再次可见时,页面的位置正在重置控件。

如果有人能告诉我如何预防这种情况,我将不胜感激。

提前致谢。

【问题讨论】:

    标签: ios objective-c uitableview uiscrollview uipagecontrol


    【解决方案1】:

    我添加了这段代码

    • (void)scrollViewDidScroll:(UIScrollView *)_scrollView { if (_scrollView == self.tableView) 返回; 在你的情况下

    • (void)scrollViewDidScroll:(UIScrollView *)_scrollView { if (_scrollView == self.sonDakikaTableView) 返回;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-29
      • 2018-09-22
      • 2019-01-11
      • 1970-01-01
      • 2020-03-09
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多