1
我已经搜索并得到了这些问题,解决了同样的问题。'ViewController'不符合协议'UITableViewDataSource'swift
但是,我不是做在回答这些提到的任何错误。
这里是我的代码:
class RightViewController: ParentViewController, UITableViewDelegate, UITableViewDataSource {
//properties
var itemsArray: [String] = ["set", "git"]
@IBOutlet var tableView:UITableView! = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
//register cell
self.tableView!.registerClass(MenuCell.self, forCellReuseIdentifier: "MenuCell")
tableView!.rowHeight = UITableViewAutomaticDimension
tableView!.estimatedRowHeight = 140
tableView!.delegate = self
tableView!.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: <TableViewDataSource>
func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemsArray.count
}
func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MenuCell", forIndexPath: indexPath) as! MenuCell
if (indexPath as NSIndexPath).row < itemsArray.count {
let option = itemsArray[(indexPath as NSIndexPath).row]
cell.titleLabel?.text = option
}
return cell
}
我已经实现了所有必需的协议方法,他们是在我的类的范围。我仍然得到这个恼人的错误。 ParentViewController
在我的代码实际上是另一个UIViewController
您应该遵循委托方法签名。 cellForRowAt用cellForRowAtIndexPath替换 –