我已将HeaderView
(来自.xib)添加到UITableView
,当我加载ViewController.But
时它会正常显示我将如何隐藏tableView标题,因为我向上滚动到任何tableView
的位置,当我向下滚动时显示HeaderView。如果有人可以帮助我,将不胜感激。以下是我的代码:
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
}
}