小编Mar*_*ngo的帖子

未从自定义类调用cellForRowAtIndexPath

我正在使用Xcode 7.0,Swift 2

我基本上是在尝试创建一个自定义类来构建一个UITable,然后在ViewController我创建一个表的新对象并将其加载到self.view中;

我遇到的问题是func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell在自定义类中根本没有调用该函数.我一直在寻找一个解决方案3天,我已经尝试重建应用程序和代码几次没有运气.

请注意,如果我在ViewController.swift文件中使用相同的代码(即构建表所需的所有内容;不包括init函数等),它可以正常工作.

我知道问题在于cellForRowAtIndexPath函数,因为它不会打印出我运行时在代码块中设置的语句.调用所有其他函数,但由于某种原因,这不会被调用.不确定我是否忽略了一些东西.任何帮助,将不胜感激.提前致谢.

class sideTest: NSObject, UITableViewDelegate, UITableViewDataSource {


    let tesTable: UITableView = UITableView()
    var items: [String]?
    var mView: UIView = UIView()

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        print("The number of rows is: \(self.items!.count)")

        return self.items!.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        print("\nLets create some cells.")

        let sCell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell!

        sCell.textLabel?.text …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift

8
推荐指数
1
解决办法
3769
查看次数

标签 统计

ios ×1

swift ×1

uitableview ×1