나는 당신이 요구하는 생각에 자상을 ... 당신과 같은 형태의 tableview (jQuery과)를 만드는 방법을 알고하는 거 싶어 해요 아래 ...하지만 반환되는 JSON에 따라 섹션 당 더 많은 또는 더 적은 수의 행을 가질 수 있어야합니다.
Section 1
action-note
actions-control
confirm
confirm
Section 2
select-conditional
select
select
action-note
actions-control
confirm
confirm
confirm
Section 3
tab-control
action-note
error-text
checkbox
actions-control
먼저 JSON 물건을 배열 배열 ([]]에 배치해야합니다. 그것은 몇 가지 구문 오류가있을 수 있으므로
'[[Section name1, row1, row2, row3, row...n],
[Section name2, row1, row2, row3, row...n],
[Section name3, row1, row2, row3, row...n]]'
jQuery과 코드는 아래와 같이 보일 것 ...
class ViewController: UIViewController, UITableViewDelegate,
UITableViewDataSource {
let arrOfArrFromJSON= '[["Section 1", "action-note", "actions-control", "confirm", "confirm"],
["Section 2", "select-conditional", row2, row3, row...n],
[Section name3, row1, row2, row3, row...n]]' //Blah blah you can fill the rest of the array out
let cellReuseIdentifier = "cell" //This is your cell identifier that was defined on the storyboard.
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return arrOfArrFromJSON.count //Counting the number of arrays within your array. Or number of sections within your array.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrOfArrFromJSON[section].count //For each section, it counts the number of rows.
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier) as UITableViewCell! //Your UITableView is called 'tableView' in this example. It could be whatever you defined it as in the storyboard.
cell.textLabel?.text = arrOfArrFromJSON[indexPath.section][indexPath.row+1] // This will name each row or cell label according to whats in your array of arrays. The +1 is to not start at your section name.
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("You tapped cell number \(indexPath.row) within section number \(indexPath.section)")//When you click on a cell it will return what cell you pressed in what section.
}
}
는이 코드를 테스트하지 않았다. 이것은 가까운 당신을 얻을 것입니다.