ループの各要素を返す方法。つまり、このループの各名前を行テキストに表示したいということです。最後の要素のみを返します。どうすればこれらすべてを返品できますか?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellFullname = tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath)
for last in lastnames {
cellFullname.textLabel?.text = "\(last)"
}
return cellFullname
}
の要素を表示するためのループは必要ありません UITableView
家系の名前の配列があるとします。
var lastnames = ["....
そして、各要素をUITableViewCellに配置します。2つのステップ:
必要なセルの量を定義します。
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return lastnames.count
}
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
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加