2016-11-22 20 views

答えて

1

は、あなたが最後の名前の配列を持っていると言います。二つのステップ:

  1. はあなたが必要とする細胞の量を定義します

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
        return lastnames.count 
    } 
    
  2. を名前でUITableView更新:

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    
        let cellFullname = tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath) 
    
    
        cellFullname.textLabel?.text = lastnames[indexPath.row] 
    
        return cellFullname 
    } 
    
0

要素arr []の配列を作成する方がよいでしょう。 使用この:

cellFullname.textLabel?.text = arr[index.row] 
2

ちょうどあなたがtextLabel.textを割り当てている部分を変更:

更新
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cellFullname = tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath) 


    cellFullname.textLabel?.text = lastnames[indexPath.row] 

    return cellFullname 
} 
0

: あなた場合だけindexPath.row.

let cellFullname = tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath) 

    cellFullname.textLabel?.text = lastnames[indexPath.row] 

    return cellFullname 
} 

を使用してlastnamesの各要素にアクセスしますcellForRowAtでforループを追加してから、ループが実行される各セルの作成に適しています。

var lastnames = [".... 

そして、あなたはのUITableViewCellの各要素を入れたい:あなたはUITableView

内の要素を表示するためのループを必要としない

関連する問題