UITableView不显示单元格。

UITableView不显示单元格。,uitableview,swift,xcode6.1,Uitableview,Swift,Xcode6.1,我已经在我的项目中用CocoaPods RESideMenu实现了,然后我创建了一个包含表的视图。我的问题是,表格不能让我看到单元格,不能给我编码,也不能让我知道哪里错了。有人能帮忙吗?我输入代码: import UIKit class RightMenuViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { var tableView = UITableView() var titl

我已经在我的项目中用CocoaPods RESideMenu实现了,然后我创建了一个包含表的视图。我的问题是,表格不能让我看到单元格,不能给我编码,也不能让我知道哪里错了。有人能帮忙吗?我输入代码:

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

    }

}

}

func tableView(…)
中,从不向单元格分配任何数据。它们为空是有道理的。

func tableView(…)
中,您从未将任何数据分配给单元格。它们为空是有道理的。

func tableView(…)
中,您从未将任何数据分配给单元格。它们为空是有道理的。

func tableView(…)
中,您从未将任何数据分配给单元格。它们是空白是有道理的。

问题在下面的一行。

self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "CELL")
这将使用重用队列中的标识符“cell”创建一个单元格,这样当您编写如下代码时

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()    
    }
单元格永远不会为零

去掉那条线,一切就完美了



问题在下一行。

self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "CELL")
这将使用重用队列中的标识符“cell”创建一个单元格,这样当您编写如下代码时

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()    
    }
单元格永远不会为零

去掉那条线,一切就完美了



问题在下一行。

self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "CELL")
这将使用重用队列中的标识符“cell”创建一个单元格,这样当您编写如下代码时

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()    
    }
单元格永远不会为零

去掉那条线,一切就完美了



问题在下一行。

self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "CELL")
这将使用重用队列中的标识符“cell”创建一个单元格,这样当您编写如下代码时

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()    
    }
单元格永远不会为零

去掉那条线,一切就完美了



您必须输入这行代码,否则将无法看到您的数组标题:

cell!.textLabel.text = titles[indexPath.row]

正确插入后,将看到菜单。

您必须输入这行代码,否则将看不到您的数组标题:

cell!.textLabel.text = titles[indexPath.row]

正确插入后,将看到菜单。

您必须输入这行代码,否则将看不到您的数组标题:

cell!.textLabel.text = titles[indexPath.row]

正确插入后,将看到菜单。

您必须输入这行代码,否则将看不到您的数组标题:

cell!.textLabel.text = titles[indexPath.row]


正确插入后,将看到菜单。

因此,在numberOfRows中,NSLog
titles.count
。检查序列图像板是否是序列图像板显示的TableViewController?自定义RightMenuViewController是Identity Inspector Alt+Cmd+3上的类吗?因此,在numberOfRows中,NSLog
titles.count
。检查序列图像板是序列图像板显示的TableViewController吗?自定义RightMenuViewController是Identity Inspector Alt+Cmd+3上的类吗?因此,在numberOfRows中,NSLog
titles.count
。检查序列图像板是序列图像板显示的TableViewController吗?自定义RightMenuViewController是Identity Inspector Alt+Cmd+3上的类吗?因此,在numberOfRows中,NSLog
titles.count
。检查序列图像板是序列图像板显示的TableViewController吗?您的自定义RightMenuViewController是Identity Inspector Alt+Cmd+3上的类吗?我删除了指示的部分代码,但是,这并不能使我看到单元格的内容,因此显示了上面显示的数组。我认为这是库RESideMenu的一个错误。@RoxyS RESideMenu中可能没有问题。我调试代码,并确保存在问题,因为您使用了“registerClass”。@RoxyS您有没有发现上面的代码没有帮助您创建单元格?如果是这种情况,我必须删除我的答案,基本上我没有把标签的菜单项放进去,事实上输入上面答案的代码,我看到标签的内容,所以菜单项。。。。。无论如何,我必须删除条目注册表类。。。。无论如何,感谢您的帮助。我删除了所示代码的一部分,但是,这并不能使我看到单元格的内容,因此显示了上面显示的数组。我认为这是库RESideMenu的一个错误。@RoxyS RESideMenu中可能没有问题。我调试代码,并确保存在问题,因为您使用了“registerClass”。@RoxyS您有没有发现上面的代码没有帮助您创建单元格?如果是这种情况,我必须删除我的答案,基本上我没有把标签的菜单项放进去,事实上输入上面答案的代码,我看到标签的内容,所以菜单项。。。。。无论如何,我必须删除条目注册表类。。。。无论如何,感谢您的帮助。我删除了所示代码的一部分,但是,这并不能使我看到单元格的内容,因此显示了上面显示的数组。我认为这是库RESideMenu的一个错误。@RoxyS RESideMenu中可能没有问题。我调试代码,并确保存在问题,因为您使用了“registerClass”。@RoxyS您有没有发现上面的代码没有帮助您创建单元格?如果是这种情况,我必须删除我的答案,基本上我没有把标签的菜单项放进去,事实上输入上面答案的代码,我看到标签的内容,所以菜单项。。。。。无论如何,我必须删除条目注册表类。。。。无论如何,感谢您的帮助。我删除了所示代码的一部分,但是,这并不能使我看到单元格的内容,因此显示了上面显示的数组。我认为这是库RESideMenu的一个错误。@RoxyS RESideMenu中可能没有问题。我调试代码,并确保存在问题,因为您使用了“registerClass”。@RoxyS您有没有发现上面的代码没有帮助您创建单元格?如果是这种情况,我必须删除我的答案,基本上我没有把标签的菜单项放进去,事实上输入上面答案的代码,我看到标签的内容,所以菜单项。。。。。无论如何,我必须删除条目注册表类。。。。无论如何,谢谢你的帮助。