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
}
}
IM檢查@Nishant Bhindi並讓ü知道不久 – anuj
檢查不起作用@Nishant Bhindi – anuj
您可以顯示分配該屬性分組後的輸出嗎? –