let identifiter = "person"
var personArray:[Person] = Array()
var tableView:UITableView!
override func loadView() {
tableView = UITableView(frame: UIScreen.main.bounds, style: .plain)
tableView.dataSource = self
tableView.delegate = self
self.view = tableView
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: identifiter)
self.creatData()
}
func creatData() {
for i in 0..<10 {
let p = Person(name: "姓名\(i)", phoneNumber: "135257046\(i)")
personArray.append(p)
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return personArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: identifiter)
cell?.textLabel?.text = personArray[indexPath.row].name
return cell!
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let detailVC = DetailViewController()
detailVC.person = personArray[indexPath.row]
self.navigationController?.pushViewController(detailVC, animated: true)
}