2017-08-31 160 views
2

我已经添加HeaderView(从.xib)到UITableView,它显示正确当我加载ViewController.But当我滚动到tableView的任何位置,当我向下滚动时显示HeaderView,我将如何隐藏tableView标题。如果有人可以帮助我,将不胜感激。下面是我的代码:如何在向上滚动和向下滚动时显示/隐藏UITableView标题?

class ViewController: UIViewController,UITableViewDataSource,UIScrollViewDelegate { 


@IBOutlet var myTable : UITableView! 
var array = ["See All Local Deals","Food & Drink","Kids Activities","Taxi" , "Shopping" , "Local Tradesmen" , "Tattoo shop" , "Car Hire" , "Health & Fitness" , "Beauty & Spas" , "Home & Garden" , "Local Services" , "Nightlife" , "Wedding Planning" , "Holiday rentals"] 

lazy var headerView : HeaderView? = { 
    return Bundle.main.loadNibNamed("HeaderView", owner: self, options: nil)?[0] as? HeaderView 

}() 

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.myTable.dataSource = self 
    self.myTable.tableHeaderView = headerView 

} 

func numberOfSections(in tableView: UITableView) -> Int { 
return 1 
} 
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return array.count 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyCell 

    cell.lblText.text = array[indexPath.row] 
    return cell 

} 
} 

回答

3

在storyboard->选择您的tableview->财产督察>而变化类型去从平原到
分组 enter image description here

+0

IM检查@Nishant Bhindi并让ü知道不久 – anuj

+0

检查不起作用@Nishant Bhindi – anuj

+0

您可以显示分配该属性分组后的输出吗? –

相关问题