在Swift,Xcode 7 beta 2中没有调用UITableViewDataSource

时间:2015-07-12 08:46:11

标签: swift uitableview

这是一个奇怪的,&我很高兴被告知我错过了一些明显的东西,但我看不到它。

首先,UITableViewDataSource方法甚至没有显示在自动完成中,然后它们不会在运行时被调用。奇怪的是,UITableViewDelegate方法正在计算两个方面。

这是(缩减)代码 -

class PopupTable : NSObject, UITableViewDataSource, UITableViewDelegate
{
    private var tableView : UITableView

    init(rect: CGRect)
    {
        tableView = UITableView(frame: rect, style: UITableViewStyle.Plain)

        super.init()

        tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "PopupCell")

        tableView.dataSource = self
        tableView.delegate = self
    }

    func show()
    {
        if let mainWindow = UIApplication.sharedApplication().delegate?.window!
        {
            mainWindow.addSubview(tableView)
        }
    }


    // MARK: TableView Delegate & DataSource

    func numberOfSectionsInTableView(tableView: UITableView) -> Int
    {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return myData.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {        
        let cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier("PopupCell")!

        cell.detailTextLabel?.text = "some text"

        return cell
    }
}

我在UIViewController中使用它没有任何问题,但这不是我想要的。

0 个答案:

没有答案