【发布时间】:2019-07-30 16:00:34
【问题描述】:
我创建了宽度为 200 的侧菜单表,我可以在其中添加标签以显示菜单项,但在这里我必须在 swift 表中的标签上方添加 uiview。
这是我的代码:
导入 UIKit
class MenuTableViewController: UITableViewController {
var selectedMenuItem : Int = 0
var menuItems = ["Home", "SignIN", "SignUp", "QR Code", "CreateBUsiness", "Services", "Employees", "Settings", "EmployeeTimeoff" ,"Billing", "Raise Request", "MYBusiness"]
override func viewDidLoad() {
super.viewDidLoad()
//Customize apperance of table view
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
tableView.separatorStyle = .none
tableView.backgroundColor = UIColor.blue
tableView.scrollsToTop = false
//Preserve selection between presentations
self.clearsSelectionOnViewWillAppear = false
tableView.selectRow(at: IndexPath(row: selectedMenuItem, section: 0), animated: false, scrollPosition: .middle)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// Return the number of sections.
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return menuItems.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "CELL")
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: "CELL")
cell!.backgroundColor = UIColor.clear
cell!.textLabel?.textColor = UIColor.white
}
cell!.textLabel?.text = menuItems[indexPath.row]//"ViewController #\(indexPath.row+1)"
return cell!
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50.0
}
}
输出是
但我需要这样:
请帮我解决这个问题。
【问题讨论】:
-
在 tableView 菜单中添加标题视图。只需搜索如何添加标题视图,您将获得大量工作示例。stackoverflow.com/questions/31964941/…
-
@channu,非常感谢,它的工作。也感谢您的链接,它对我有用。
-
WC..快乐编码
标签: swift uitableview uiview side-menu