当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - How to display two arrays in two different cells in UITableView using swift3

问题描述:

I am trying to display two arrays in two different cells in a table view but it doesn't works , can any one help me to solve this problem , I am using Xcode8 and Swift3 , and this is my TableView code .

My code :

 import UIKit

class _CellsTableViewController: UITableViewController {

var array1 = [String]()

var array2 = [String]()

override func viewDidLoad() {

super.viewDidLoad()

array1 = ["aaa","bbb","ccc","ddd","eee","fff"]

array2 = ["11111","22222","33333"]

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {

// #warning Incomplete implementation, return the number of sections

return 1

}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return array1.count + array2.count

}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

if indexPath.row == 0 {

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

cell.textLabel?.text = array1[indexPath.row]

return cell

}

else {

let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath)

cell.textLabel?.text = array2[indexPath.row]

return cell

}

}

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: