简体   繁体   English

将顶视图添加到UITableview并将其滚动到导航栏的底部

[英]Add a top view to UITableview and scroll it to bottom of navigationbar

I Have created a view and added to subview of UITableview - 我已经创建了一个视图并将其添加到UITableview的子视图中-

 topView = UIView(frame: CGRectMake(0, 250, self.myTableView.frame.width, 44)) 
        topView.backgroundColor = UIColor.redColor() 
        self.view.addSubview(topView) 
        self.view.bringSubviewToFront(topView) 
         
        self.myTableView.contentInset = UIEdgeInsetsMake(294, 0, 0, 0) 

Now I want to scroll this view to the bottom of navigationBar so I have written scrollview delegete method- 现在,我想将此视图滚动到navigationBar的底部,因此我编写了scrollview delegete方法-

 func scrollViewDidScroll(scrollView: UIScrollView){ 
        var rect:CGRect = topView.frame; 
        if myTableView.contentOffset.y <= -98 { 
       rect.origin.y = (myTableView.contentOffset.y * -1) - rect.size.height 

            topView.frame = rect 
        } 
    } 

=> Here try following code.. =>在这里尝试以下代码。

UIView *myProgView = (UIView *)self.progView; //progView is a method that returns a UIView

[self.tableView insertSubview:myProgView aboveSubview:self.tableView]; 

[self.tableView bringSubviewToFront:myProgView];

=> do tableView Scroll position : =>做tableView滚动位置:

 if numberOfRows > 0 {

 let indexPath = NSIndexPath(forRow: numberOfRows-1, inSection: (numberOfSections-1))

 self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: animated)
 }
  1. I found another solution, i have created 2 sections in tableview. 我找到了另一个解决方案,我在tableview中创建了2个部分。 In first section, returned 1 cell which size is equal to the top inset of my tableview. 在第一部分中,返回了1个单元格,其大小等于我的tableview的顶部插图。 I didn't give height to 0th section. 我没有将高度设为0。
  2. In second section i have added my specific height and some number of rows in my tableview. 在第二部分中,我在表视图中添加了特定的高度和一定数量的行。

Now i am able to scrolling my desired view into the tableview section. 现在,我可以将所需的视图滚动到tableview部分。

Thanks 谢谢

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

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