永远不会调用cellForRowAtIndexPath

时间:2014-09-07 23:52:48

标签: swift ios8 xcode6-beta7

我正在使用Xcode 6 beta 7.我有一个故事板,其中包含UIViewController,它有UITableview和UITableViewCell,所有内容都正确连接,我已经为UIViewController提供了所有必需的代码。

当我在模拟器中运行应用程序时,其中一个数据源函数" cellForRowAtIndexPath"永远不会被调用,但是" numberOfRowsInSection"被称为

  • " func tableView(tableView:UITableView,numberOfRowsInSection section:Int) - > INT"被称为
  • 但" func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath) - >的UITableViewCell" 永远不会被打电话

以下是我的视图控制器代码:

import UIKit

class DVViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{

    @IBOutlet var tableView : UITableView?
    var tableData = ["Row 1", "Row 2", "Row 3"]
    let kCellID = "cell"

    override func viewDidLoad()
    {
        super.viewDidLoad()

        self.tableView?.delegate = self;
        self.tableView?.dataSource = self;

        //load cell
        self.tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: kCellID);
        self.tableView?.reloadData();
    }

    //MARK: Tableview delegates
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return self.tableData.count;
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
       //var cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: kCellID)
        let cell : UITableViewCell = UITableViewCell (style: UITableViewCellStyle.Default, reuseIdentifier: kCellID);
        return cell;
    }
}

有人可以建议为什么" cellForRowAtIndexPath"永远不会被调用,它曾经在Xcode6 beta 2中工作。

3 个答案:

答案 0 :(得分:3)

这是我做的,卸载了Xcode 5& 6只重新安装的Xcode 6,Ran项目和它工作。经过2天的调试后,重新安装完成了这个技巧。

答案 1 :(得分:2)

我刚检查过你的代码,它确实有效。
检查是否调用numberOfRowsInSection。如果没有,请检查storyboard中的连接。

答案 2 :(得分:0)

尝试一下:

MainViewController类:UIViewController,UITableViewDataSource,UITableViewDelegate {

func viewDidLoad(){

super.viewDidLoad()

tableView.dataSource =自我

tableView.delegate =自我

}

}