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替換 –