动物表单详情
2020-02-14 本文已影响0人
授之以渔不如授之以鱼
'''
//
// AnimalTableViewController.swift
// tableView
//
// Created by 雪衣侯 on 2/14/20.
// Copyright © 2020 雪衣侯. All rights reserved.
//
import UIKit
class AnimalTableViewController: UITableViewController {
let animalArray = ["cat","chicken","dog","elephant","fox","goat","kangaroo","monkey","mouse","penguin","rabbit","snail"]
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
// 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 {
// #warning Incomplete implementation, return the number of rows
return animalArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = animalArray[indexPath.row]
cell.imageView?.image = UIImage(named: animalArray[indexPath.row])
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showDetail", sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail"{
//dvc是destination view controller的缩写的意思
let dvc = segue.destination as? DetailViewController
let selectIndexPath = self.tableView.indexPathForSelectedRow
if let selectRow = selectIndexPath?.row{
dvc?.infoFromeViewOne = animalArray[selectRow]
//标题
dvc?.navigationItem.title = animalArray[selectRow]
}
}
}
}
'''
'''//
// DetailViewController.swift
// tableView
//
// Created by 雪衣侯 on 2/14/20.
// Copyright © 2020 雪衣侯. All rights reserved.
//
import UIKit
class DetailViewController: UIViewController {
var infoFromeViewOne:String?
@IBOutlet weak var myImageView: UIImageView!
@IBOutlet weak var myLable: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
myLable.text = infoFromeViewOne
if let okimageName = infoFromeViewOne{
myImageView.image = UIImage(named: okimageName)
}
// Do any additional setup after loading the view.
}
}
'''