現在、swiftで衣装リストを制作しております。
各セルにテキストだけでなく、それぞれの服の画像を表示させたいのですが、どのように記述すればいいのかがわかりません。
教えていただけますでしょうか?
よろしくお願いします。
import UIKit let sectionTitle = ["ジャケット","スーツ・ベスト","トップス(長袖シャツ)"] let section0 = [("1、ジャケット","レディース"),("2、ジャケット","レディース"),("3、ジャケット","メンズ")] let section1 = [("1、スーツ","レディース"),("2、スーツ","レディース"),("3、スーツ","メンズ")] let section2 = [("1、長袖シャツ","レディース"),("2、長袖シャツ","レディース"),("3、長袖シャツ","レディース")] let tableData = [section0, section1, section2] class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { override func viewDidLoad() { super.viewDidLoad() let myTableView:UITableView! myTableView = UITableView(frame: view.frame, style: .grouped) myTableView.delegate = self myTableView.dataSource = self view.addSubview(myTableView) } func numberOfSections(in tableView: UITableView) -> Int { return sectionTitle.count } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { let sectionData = tableData[section] return sectionData.count } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sectionTitle[section] } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell") let sectionData = tableData[(indexPath as NSIndexPath).section] let cellData = sectionData[(indexPath as NSIndexPath).row] cell.textLabel?.text = cellData.0 cell.detailTextLabel?.text = cellData.1 return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let title = sectionTitle[indexPath.section] let sectionData = tableData[indexPath.section] let cellData = sectionData[indexPath.row] print("(title)(cellData.1)") print("(cellData.0)") } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。