我已經在CocoaPods RESideMenu的項目中實現了,然後創建了一個包含表格的視圖。我的問題是,桌子不讓我看到細胞,xcode我沒有錯誤,然後不知道我錯了。誰能幫忙?我輸入代碼:UITableView不顯示單元格。
import UIKit
class RightMenuViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var tableView = UITableView()
var titles = ["Home","Profilo","Notizie","Impostazioni"]
//var images = ["IconHome","IconCalendar","IconProfile","IconSettings","IconEmpty"]
init(frame: CGRect, dialStrings: [String]) {
super.init(nibName: nil, bundle: nil)
self.tableView = UITableView(frame: CGRectMake(0, (frame.size.height - 54 * 2)/2.0, frame.size.width, 54 * 2), style:UITableViewStyle.Plain)
}
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth
self.tableView.contentInset = UIEdgeInsetsMake(100.0, 0, 0, 0)
//contentInset = UIEdgeInsetsMake(64.0, 0, 0, 0)
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.opaque = false
self.tableView.bounces = false
self.tableView.backgroundColor = UIColor.redColor()
self.tableView.separatorStyle = .None
self.tableView.backgroundView = nil //UIImageView(image: UIImage(named: "BackMenu"))
self.tableView.scrollsToTop = false
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "CELL")
view.addSubview(self.tableView)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 54.0
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return titles.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as? UITableViewCell
if (cell == nil){
cell = UITableViewCell()
cell!.backgroundColor = UIColor.blueColor()
cell!.textLabel.font = UIFont(name: "HelveticaNeue", size: 21)
cell!.textLabel.textAlignment = NSTextAlignment.Right
cell!.textLabel.textColor = UIColor.whiteColor()
cell!.textLabel.highlightedTextColor = UIColor.lightGrayColor()
cell!.selectedBackgroundView = UIView.alloc()
}
return cell!
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main",bundle: nil)
var salViewController: UIViewController
switch (indexPath.row){
case 0:
salViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("Home") as UIViewController
break
case 1:
salViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("Profilo") as UIViewController
break
case 2:
salViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("Notizie") as UIViewController
break
case 3:
salViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("Impostazioni") as UIViewController
break
default:
break
}
}
}
因此,在numberOfRows,NSLog'titles.count'中。 – 2014-12-13 02:55:27
檢查故事板是由故事板呈現的TableViewController嗎?您的自定義RightMenuViewController是Identity Inspector Alt + Cmd + 3上的類嗎? – 2014-12-13 03:33:01