그래,이 사이트를 내 문제의 해결책을 찾기 위해 수색 해왔다. 하나를 찾았지만 어떤 이유로 든 코드가 의도 한대로 작동하지 않습니다. 내 목표는 테이블 뷰에 섹션이있는 것입니다. 각 섹션 아래에는 각 섹션에있는 셀의 양 (예 : 한 섹션에는 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
}
}
내 목표는 2 diffferent 헤더, 테스트 및 testtt
테스트 제목이와 자막 정보 1 등
와 셀을해야합니다을 가지고 내 코드입니다무엇이 엉망이됩니까? How do I populate two sections in a tableview with two different arrays using swift?
(/ 40 upvotes w 응답)
'UITableViewDataSource' 또는'UITableViewDelegate' 메소드가 호출되고 있습니까? – AdamPro13
네, 그렇게 생각합니다. 표는 첫 번째 섹션과 셀만 채 웁니다. 섹션으로 '테스트', 설명으로 'this', 부제로 '정보 1', 나머지는 표시되지 않습니다. –
@GaryMakin that 's 그가'UITableViewController'를 사용하는 대신 뷰 컨트롤러의 서브 뷰로'UITableView'를 추가했다면 사실이 아닙니다. – AdamPro13