2016-04-06 13 views
-3

私はテーブルビューコントローラのセルに名前の配列を提示しようとしています。 TableViewコントローラ - スウィフト

import UIKit 

class TableViewController: UITableViewController 
{ 

    var names = ["aA", "aB", "cC"] 

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int 
    { 
     return 0 
    } 

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


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    { 
     let cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath) 
     cell.detailTextLabel!.text = names[indexPath.row] 
     return cell 
    } 
} 

私はそれをシミュレート

は、何も細胞内に登場していない:

は、ここでは、コードです! As in the image here

私のコードに間違いがあります。 コンパイラは私にエラーを与えませんでした。

+3

numberOfSectionsInTableView ... 1を返すか、完全に変更した後numberOfSectionsをそのメソッド –

+0

を削除し、あなたのクラスにストーリーボードにビューをリンクするかどうかを確認します。 – UlyssesR

+0

@EICaptainチェックデータソース/デリゲート*は、ここでは不要です。ここでは、 'UITableViewController'サブクラスを扱っています。 – nhgrif

答えて

2

セクションの数を更新しました。あなたの問題は解決されます。

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return 1 
} 
+2

またはメソッドを完全に削除します。 – nhgrif

+0

デリゲートとデータソースを現在のビューコントローラに設定しましたか? –

+0

このメソッドを削除した後で動作します。 – Mariah