Swift中當你設(shè)置完UITableView的代理和數(shù)據(jù)源
class ViewController: UIViewController,MAMapViewDelegate,AMapSearchDelegate,
UITableViewDelegate,UITableViewDataSource {
lazy var tableView: UITableView! = {
var tableView = UITableView(frame: CGRectZero, style: UITableViewStyle.Grouped)
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier: "Cell")
return tableView
}()
}
并且你也添加了UITableViewSource這個協(xié)議, 但仍然報下面的錯誤.
Type 'ViewController' does not conform to protocol 'UITableViewDataSource'
Why ?
因為你沒有實現(xiàn)協(xié)議里面的Requred 方法, 所以提示抱錯, 不過個人覺得這樣的報錯提示很不友好...

DAD132FC-38A9-491E-8C97-5EB40267DF59.png
最后你的代碼改成如下, 報錯就會消失.
class ViewController: UIViewController,MAMapViewDelegate,AMapSearchDelegate,
UITableViewDelegate,UITableViewDataSource {
lazy var tableView: UITableView! = {
var tableView = UITableView(frame: CGRectZero, style: UITableViewStyle.Grouped)
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier: "Cell")
return tableView
}()
//MARK: UITableViewDelegate
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
return cell
}
}