私はこのサイトを精査して問題を解決しています。私は1つを見つけましたが、コードによって何らかの理由で意図した通りに動作しません。私の目標は、その中のセクションを持つテーブルビューを持つことです。各セクションの下には、各セクションの異なる量(1つのセクションに1つと他のセクションに3つのセルなど)があります。ここでそれぞれの細胞の量が異なるセクションを作る方法
は私のコードは私の目標は、2つのdiffferentヘッダを持つことで、テストおよびtesttt
テストはタイトルこのサブタイトル情報1で細胞を持っているので、
になりますimport UIKit
class cat1: UIViewController, UITableViewDelegate, UITableViewDataSource {
let proc = [["this"], ["Ye", "it", "will"]]
let infor = [["info 1"] , ["info 3", "info 2" , "info 4"]]
let arrayforsec = [ "test", "testtt"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return proc[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as UITableViewCell
let cellText = proc[indexPath.section][indexPath.row]
let descriptiontxt = infor[indexPath.section][indexPath.row]
cell.detailTextLabel?.numberOfLines = 0
cell.detailTextLabel?.lineBreakMode = .byWordWrapping
cell.textLabel?.text = cellText
cell.detailTextLabel?.text = descriptiontxt
return (cell)
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section :Int) -> String?{
return arrayforsec[section]
}
func numberOfSectionsInTableView(in tableView: UITableView) -> Int {
return proc.count
}
}
です
何がうんざりですか?ここ
は、私が相談のソリューションです:How do I populate two sections in a tableview with two different arrays using swift?
(/ 40 upvotes W応答)
'UITableViewDataSource'または' UITableViewDelegate'メソッドのいずれかが呼び出されていますか? – AdamPro13
はい、私はそうだと思うので、テーブルは最初のセクションとセルだけを読み込みます。セクションとして "test"、 "description"として "info 1"、残りはちょうど表示されません... –
@GaryMakin that's彼が 'UITableViewController'を使うのではなく、' UITableView'をビューコントローラのサブビューとして追加した場合は真です。 – AdamPro13