没有可访问的初始值设定项(UITableView)

时间:2016-09-16 21:10:22

标签: ios swift uitableview generics

我对Swift中的仿制药不熟悉。

class MyTableViewController<Element>: UITableViewController {
    var data = [Element]()
}
class AnotherTableViewController: MyTableViewController<String> {}

MyTableViewController仅覆盖numberOfRowsInSectiondidSelectRowAtIndexPath

当我尝试显示AnotherTableViewController时,这是我尝试初始化时遇到的错误:...cannot be constructed because it has no accessible initializers

我不明白为什么我会收到此错误,因为我的所有成员变量都已初始化。有谁知道我为什么会收到这个错误?

由于

修改

这是实际的代码:

    class CRTableViewController<Element>: UITableViewController {

        var collecting = false {
            didSet {
                switchCollectingMode()
            }
        }

        var data = [Element]()
        var collectedData = [String:Element]()

        private func switchCollectingMode() {
            tableView.allowsMultipleSelection = collecting
            title = collecting ? "Collect Mode" : "Normal Mode"
            if !collecting {
                for (key, _) in collectedData {
                    let indexPath = NSIndexPath(forRow: Int(key)!, inSection: 0)
                    tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .None
                }
                collectedData.removeAll()
            }
        }

        // MARK: - Table view data source

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

        override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
            let cell = tableView.cellForRowAtIndexPath(indexPath)

            if collecting {
                if cell?.accessoryType == .Checkmark {
                    cell?.accessoryType = .None
                    collectedData.removeValueForKey(String(indexPath.row))
                } else {
                    cell?.accessoryType = .Checkmark
                    collectedData[String(indexPath.row)] = data[indexPath.row]
                }
            } else {
                cell?.accessoryType = .None
            }

            tableView.deselectRowAtIndexPath(indexPath, animated: true)
        }

    }
class CREventsTableViewController: CRTableViewController<Event> {

    var model: ChronoModel!
    var eventsReferense: FIRDatabaseReference!

    override func viewDidLoad() {
        super.viewDidLoad()

        let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
        model = delegate.model

        eventsReferense = model.databaseReferense.child("events")
    }

    // MARK: - Table view data source

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

        let event = data[indexPath.row]

        cell.textLabel?.text = event.title

        return cell
    }
}

这就是错误发生的地方: enter image description here

0 个答案:

没有答案