我正在学习编写没有故事板的代码,我决定将Side Bar添加到我的项目中。我使用了ENSwiftSideMenu库,他们提供的示例使用了故事板。
我试着写它没有它显示侧栏但我有一个问题。我的侧边栏实际上是一个tableviewController,它应该有2个单元格但是当我打开我的侧栏时它并没有显示我的单元格。但它打印到记录它添加这些单元格。 (我添加了打印方法)。
那么,如果可能的话,我怎样才能让我的细胞可见?
import UIKit
class MenuTableViewController: UITableViewController {
var arr = [String]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0)
arr.append("Lesson 1")
arr.append("Lesson 2")
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return arr.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
print("I am calling you")
let cell = MyTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "reuseIdentifier")
//let cell = UITableViewCell(
cell.textLabel!.text = self.arr[indexPath.row]
print(self.arr[indexPath.row])
// Configure the cell...
return cell
}
}
import UIKit
import ENSwiftSideMenu
import Cartography
class SideNavigationViewController: ENSideMenuNavigationController {
init(){
// super.init(coder: NSCode)
super.init(menuViewController: TempViewController(), contentViewController: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
var menu = MenuTableViewController()
menu.view.frame = CGRect(x: 0, y: 0, width: 180, height: 180)
sideMenu = ENSideMenu(sourceView: self.view, menuViewController: menu, menuPosition: ENSideMenuPosition.Left)
sideMenu!.menuWidth = 180
view.bringSubviewToFront(navigationBar)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}