2017-01-07 8 views
0

の未解決の識別子table viewprototype cellを「cell」に設定してthe main storyboardを設定しました。テーブルビューはdata source outletdelegate outletです。
11行目にテーブルビューを作成すると、「未解決の識別子」のためにビルドが毎回クラッシュします(下記のコードを参照)。TableViewCell私のXcodeプロジェクトでセルを作成するときに、

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource 
{ 

let array = createArray() 

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    cell = UITableViewCell(style: UITableViewStyle.default, reuseIdentifier: "cell") |"ERROR: Unknown Identifier 'cell' " 
    cell.textlabel?.text = "" 
    return cell 
} 

誰もがこのエラーを知り、助けてくれるのですか?

+1

ためのコードの下に使用することは、それはありません、return' 'の後に括弧を使用しないでください。例えば関数'return validDeck.count' – vadian

答えて

2

SWIFT 3. *

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return validDeck.count // assuming count must be greater then 0 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell 

cell.textlabel?.text = "Cell tittle" 
    return cell 
} 
+0

'mTableView私のViewControllerには属性mTableView ... – Narusan

+1

@Narusan Delete ':UITableViewCell'(無用な注釈、コンパイラが型を推論することができる)があり、' self.mTableView.'を 'tableView.'に置き換えます。 **最初のパラメータとして渡されたテーブルビューのインスタンス – vadian

+0

@vadianあなたは何を意味するのかを明確にするために編集できますか?私はかなり理解していません。残っているのはデキュー・コールです。 – Narusan

1

UITableViewCellインスタンスを直接初期化することはありません。 viewDidLoad

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") 

、その後:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for indexPath: indexPath) 
    cell.textlabel?.text = "" 
    return(cell) 
} 
+0

viewDidLoadの' tableview_(numberOfRowsInSection) 'メンバへの2つのエラー:'あいまいな参照 'と' cell = tableView.dequeueReusableCell(wi ... ')が動作しない、Xcodeはfor ...私はSwift3を使用していますが、これが理由でしょうか? – Narusan

+0

Interface Builderで設計されている場合は、セルを登録する必要はありません – vadian

+1

@Narusan oops私はletを忘れていました、編集済み –

関連する問題