2014-09-29 48 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

相關問題