2016-05-06 8 views
0

私はすでに別のビューで同じテーブルビューを行っていますが、このビューでは動作しませんでした。私も解決策を探していますが、私はタイプviewcontrollerはプロトコルuitableviewdatasourceに準拠していません

クラスHistoryViewController動作しないのか分からない:のUIViewController、UITableViewDelegate、UITableViewDataSourceを{

@IBOutlet weak var tableview: UITableView! 

var date = ["ciao", "muori"] 
var place = ["aaaa"] 



override func viewDidLoad() { 
    super.viewDidLoad() 

    tableview.dataSource = self 
    tableview.delegate = self 

    // Do any additional setup after loading the view. 
} 


override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

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

func tableview(tableView: UITableView, cellForRowIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = self.tableview.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! HistoryCell 
    cell.placeLabel.text = place[indexPath.row] 
    cell.dateLabel.text = date[indexPath.row] 
    return cell 

} 


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) 
{ 

} 

誰かが私を助けることができますか?

+0

ファイルを共有することは可能ですか? – harshitgupta

+1

'tableView:cellForRowAtIndexPath:'の代わりに 'tableview:cellForRowIndexPath:'を実装しました。 – dan

答えて

0

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 

func tableView(tableView:UITableView, numberOfRowsInSection section:Int) 

がクラス{}括弧内に挿入されているかどうかを確認してください。

1

tableView:cellForRowAtIndexPath:ではなくtableview:cellForRowIndexPath:を実装する必要があります。メソッド名に間違いがあります。

class HistoryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

    @IBOutlet weak var tableview: UITableView! 

    var date = ["ciao", "muori"] 
    var place = ["aaaa"] 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     tableview.dataSource = self 
     tableview.delegate = self 

     // Do any additional setup after loading the view. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

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

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = self.tableview.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! HistoryCell 
     cell.placeLabel.text = place[indexPath.row] 
     cell.dateLabel.text = date[indexPath.row] 
     return cell 
    } 

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) 
    { 
    } 
} 
3
  • 後藤課題ナビゲーター(⌘4):ここでは正しい実装です。
  • エラーメッセージの横にある開閉用の三角形を開きます。
  • エラーメッセージの下に表示される必須の欠落メソッドを実装します。

これらの誤植を避けるためにコード補完を使用してください。

関連する問題