Section Headers in UITableView when inset of tableview is changed

前端 未结 4 2013
刺人心
刺人心 2021-02-01 07:18

I have implemented a \"Pull to refresh\" in my tableView like the iPhone app Twitter or Facebook.
My tableView has sections with head views. When the tableView is in \"Refre

相关标签:
4条回答
  • 2021-02-01 07:42

    I had the same problem when using contentInset and fixed it by adding code to scrollViewDidScroll: to update the contentInset dynamically while in the "loading" state.

    if( refreshState == kLoading ) {
        if( scrollView.contentOffset.y >= 0 )
            scrollView.contentInset = UIEdgeInsetsZero;
        else
            scrollView.contentInset = UIEdgeInsetsMake( MIN( -scrollView.contentOffset.y, kPullHeight ), 0, 0, 0 );
    }       
    
    0 讨论(0)
  • 2021-02-01 07:47

    Looks like an UIKit bug. Found a workaround:

    // your initial inset
    let kInset = 40.0
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let offset = scrollView.contentOffset.y
        if (offset < 0) {
            scrollView.contentInset = UIEdgeInsets(top: kInset, left: 0.0, bottom: 0.0, right: 0.0)
        } else {
            scrollView.contentInset = .zero
        }
    }
    
    0 讨论(0)
  • 2021-02-01 07:51

    Try this way to add push view controller.

    • Create a table view controller and add it as the sub view of existing view controller.
    • Then assign your table view and refresh controllers to tableview controller's properties.

      UITableViewController *newTableViewController = [[UITableViewController alloc] init];
      newTableViewControler.tableView = <yourTableView>;
      
      <yourRefreshController> = [[UIRefreshControl alloc] init];
      [<yourRefreshController> addTarget:self
                                  action:@selector(refreshTableView:)
                        forControlEvents:UIControlEventValueChanged];
      
      newTableViewController.refreshControl = _chatListRefreshControl;
      [self addChildViewController:newTableViewController];
      
    0 讨论(0)
  • 2021-02-01 07:58

    When doing this, I usually use the table-wide header in UITableView instead:

    @property(nonatomic, retain) UIView *tableHeaderView
    

    ...instead of contentInsets. There were a lot of bugs with contentInsets all the way back to iOS 2.x days, and I'm not sure they've all been fixed. Is there a reason you can't use a table header?

    0 讨论(0)
提交回复
热议问题