學習筆記:ios開發導航欄和tableView中間新增view的問題
1.需求分析
如圖所示,導航欄和tableView中間添加了一個日期的view,無法用UITabBarController來實現

2.實現原理
用UIViewController作為根檢視新增導航欄檢視,普通view檢視和tableview檢視,然後在檢視上新增控制元件
2.1.xib構圖
分別新增UINavigationBar,View,UITableView三個檢視

2.2根檢視中實現資料來源和代理
override func viewDidLoad() {
super.viewDidLoad()
//設定tableview的位置
tableViewP.frame=CGRect(x: 0, y: 0, width:self.view.bounds.size.width, height: self.view.bounds.size.height-90)
tableViewP.delegate = self
tableViewP.dataSource = self
// 導航條標題設定
roomId.title = self.METTINGROOM_ID
//註冊xib
let cellNib = UINib(nibName: "MeetingroomBookInfoPTableViewCell", bundle: nil)
tableViewP.register(cellNib, forCellReuseIdentifier: "CellIdentifier")
}
/// 導航條返回
@IBAction func clickBack(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
// MARK: - Table view data source
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
// cell的個數
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return meetingList1?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier" ,for: indexPath) as! MeetingroomBookingInfoPTableViewCell
cell.bookingbtn.setTitle("點選預約", for: UIControlState.normal)
.....................
return cell
}