2014-09-29 50 views
0

错误:Type "MapListDataSource" does not conform to protocol "UITableViewDataSource"TableviewDataSource在自己的文件不符合协议UITableViewDataSource在迅速

import Foundation 
import UIKit 
import CoreData 

class MapListDataSource: NSObject, UITableViewDataSource { 
    func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 1 
    } 
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell") 
     return cell 
    } 
} 

我试过执行的,你需要有UITableViewDatasource功能的最小量,仍然编译器将不接受它。这不是在视图控制器中实现的,数据源被分割到它自己的文件中。为什么它不符合协议?这两种方法是最低要求的权利?

回答

0

您必须添加所需的方法。

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 1 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell") 
     return cell 
    } 
+0

居然有这样的方法,但有老!从较旧的实现。谢谢! – hakonbogen 2014-09-29 09:06:09

相关问题