2017-07-22 3 views
-1

正しいです助けてください、私は私のウィットの終わりです。私は複数のチュートリアルに従っていますが、これに似たスレッドをすべて読み込み、5時間後にはまだ失われ、同じエラーが表示されます。「ViewControllerタイプがUITableViewDataSourceに準拠していません。XCODE:UITableViewDataSourceに準拠していない - の方法は正しいです、{}

コード:

import UIKit 

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

@IBOutlet var proTable: UITableView! 



override func viewDidLoad() { 
    super.viewDidLoad() 
    proTable.reloadData() 

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 
     return pcMgr.pros.count 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ 
     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "Default Pros") 

     cell.textLabel?.text = pcMgr.pros[indexPath.row].name 

     return cell 
    } 

    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){ 
     if (editingStyle == UITableViewCellEditingStyle.delete){ 

      pcMgr.pros.remove(at: indexPath.row) 
      proTable.reloadData() 
     } 
     } 
} 

} 
+1

は、あなたがのviewDidLoad内の関数を入れて、あなたの 'viewDidLoad'ブラケット –

+1

をチェックし、それらを移動し、あなたが行くように良いことがあります。 – HAS

答えて

1

あなたのコードをこれに置き換えて、古い構文を内部に使用しましたviewDidLoad機能。

のviewDidLoad()からの機能-Remove
import UIKit 

class ViewController : UIViewController, UITableViewDelegate, UITableViewDataSource { 

    @IBOutlet var proTable: UITableView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     proTable.reloadData() 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "Default Pros") 

     cell.textLabel?.text = pcMgr.pros[indexPath.row].name 

     return cell 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

     return pcMgr.pros.count 
    } 

    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){ 
     if (editingStyle == UITableViewCellEditingStyle.delete){ 
      pcMgr.pros.remove(at: indexPath.row) 
      proTable.reloadData() 
     } 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
    } 
} 
+0

ありがとう、これはそれでした! – Jordan

0

構文必要UITableViewDataSource mehodsためには正しくありません。 これを試してみてください:

@available(iOS 2.0, *) 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     <#code#> 
    } 

    @available(iOS 2.0, *) 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     <#code#> 
    } 

すでにプロトコルに準拠しているので、私はメソッド宣言にはXCodeの自動補完を使用することをお勧めします。メソッドの宣言を確認するために、エスケープキーを使用してください。

0

スイフト3におけるプロトコル機能の正しい構文

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
let cell ; 
return cell 
} 

viewDidLoadメソッドの外これらの方法を使用します。これらのメソッドは、あなたのviewDidLoad内にある必要があります。

0

-Mention配列

-Addコード

このことができます希望する機能 "numberOfSections"!

import UIKit 

class ViewController: UIViewController , UITableViewDelegate, UITableViewDataSource{ 

    @IBOutlet var proTable: UITableView! 
    var pcMgr: Array = [] // Or whatever your array is! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     proTable.reloadData() 
    } 

    func numberOfSections(in tableView: UITableView) -> Int { 
     1 
} 
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 
     return pcMgr.pros.count 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ 
     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "Default Pros") 

     cell.textLabel?.text = pcMgr.pros[indexPath.row].name 

     return cell 
    } 

    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){ 
     if (editingStyle == UITableViewCellEditingStyle.delete){ 

      pcMgr.pros.remove(at: indexPath.row) 
      proTable.reloadData() 
     } 
    } 

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

} 
関連する問題