简体   繁体   English

ios:UITableView不会滚动到底部

[英]ios:UITableView wont scroll to bottom

I have a scroll view with 3 UITableViews in it for paging. 我有一个滚动视图,其中有3个UITableViews用于分页。 All of the UITableViews loads more cells of data. 所有UITableViews加载更多数据单元。 The first UITableView loads more cells than the other two. 第一个UITableView加载的单元格比其他两个更多。 When viewing this first UITableView I am able to scroll to the bottom, but when I scroll to a second UITableView and back to the first UITableView I can no longer scroll all the way down. 当查看第一个UITableView我可以滚动到底部,但是当我滚动到第二个UITableView并返回到第一个UITableView我将无法一直向下滚动。 It seems as though I have to resize my scroll view. 好像我必须调整滚动视图的大小。 Why can't I scroll to the bottom after a view refresh? 视图刷新后为什么不能滚动到底部? Any help would be great. 任何帮助都会很棒。

*The first UITableView has a search bar at the top. *第一个UITableView在顶部有一个搜索栏。 The other two do not. 其他两个没有。 I tried removing the search bar, but the error still occurs. 我尝试删除搜索栏,但仍然出现错误。

//Create a frame for each page and add the page to the scroll view
- (void)frameToScrollView{

if (pages!=NULL) {

    for (int i = 0; i < pages.count; i++) {

        //Get the current view controller
        UITableViewController *controller = [pages objectAtIndex:i];

        //Create a frame for the current table view controller
        CGRect frame = controller.view.frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;
        controller.view.frame = frame;

        //Add the the current table view controller page to the scroll view
        [self.scrollView addSubview:controller.view];
    }
  }
}

Set Other properties: 设置其他属性:

//Set the properties for the scroll view
- (void)setScrollViewProperties{
     self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * pages.count,     self.scrollView.frame.size.height);
    self.scrollView.contentOffset = CGPointMake(self.scrollView.frame.size.width, 0);
    self.scrollView.scrollsToTop = NO;
}

UITableView is a subclass of UIScrollView . UITableViewUIScrollView的子类。 So you are basically adding 3 scrollviews to a scrollview. 因此,您基本上是将3个滚动视图添加到一个滚动视图。 I dont think this is advisable. 我认为这是不可取的。

I think the problem here is that the device is confused as to which scrollView will handle the touch/drag event. 我认为这里的问题是设备对哪个scrollView将处理触摸/拖动事件感到困惑。

If you really need the scrollView for paging, I suggest you create the scrollView, but disable touch event for this. 如果确实需要使用scrollView进行分页,建议您创建scrollView,但是为此禁用触摸事件。 You can add buttons to allow page navigation (instead of allowing user to do left/right swipe). 您可以添加按钮以允许页面导航(而不是允许用户左右滑动)。 This way, you can ensure that only the tableview that is visible is going to get the touch/drag event. 这样,您可以确保只有可见的表视图才能获取touch / drag事件。

Found similar problem here: UITableView Won't Scroll In Certain Conditions . 在这里发现了类似的问题: UITableView在某些情况下不会滚动

My first UITableView has a search bar at top. 我的第一个UITableView在顶部有一个搜索栏。

In the post above they recommend adding [self.tableView setAlwaysBounceVertical:YES]; 在上面的帖子中,他们建议添加[self.tableView setAlwaysBounceVertical:YES];

I tested this and it does not work. 我对此进行了测试,但无法正常工作。 I put it in my view did load for the UITableView. 我把它放在我的视图中确实为UITableView加载了。

Got it working: 得到它的工作:

(1) After "load more" cell is clicked and information is received I remove all subviews (1)单击“加载更多”单元格并收到信息后,我删除所有子视图
(2) Then I create new frames and add them back to the subview (2)然后创建新框架并将其添加回子视图
(3) Last I reload the table data (3)最后我重新加载表数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM