2017-12-31 34 views
-4

私はこの問題をどのように知っているのか知りたがっています。各行の配列に値を表示

数字の配列(1〜50)を作成し、各番号をView Controllerの異なる行に表示しようとしています。

私はロードバンプを実行していますが、戻り値が必要であることをXcodeが示唆していますが、forループの外側に戻り値を置くと、認識されません(画像参照)。すべての

enter image description here

+0

'for i in numbers {'ループと閉じ括弧 '}'を削除し、 'String(i)'を 'numbers [indexPath.row]'に変更します。 –

答えて

-1

まずこの

var numbers = Array(0...50) 

のような整数の配列を作成し、

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = UITableViewCell(style: .default, reuseIdentifier: "Cell") 
    // since this method is called each time a cell is about to display so for loop is not the correct way set text to a textLabel 
    cell.textLabel?.text = String(numbers[indexPath.row]) 
    return cell 
} 

してcellForRowAt方法を交換してください、あなたのデータソースがあなたのUIViewControllerに接続されていることを確認しますそうしないと、UITableViewでデータを見ることができなくなります。

関連する問題