I am trying to change the button and its function depending on the cell that is tapped. Currently, I have a list of hospitals that the user will see. The clicked cell will open up a detail consisting of two labels, an image and a button. Everything works as typed except the button. I would like it to change per cell to match the phone number of the given hospital. Any ideas?
import UIKit
var hospital = ["Mercy Medical Center"]
var hospitalDesc = ["Roseburg"]
var myIndex = 0
class PhoneBookTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return hospital.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PBCell", for: indexPath)
cell.textLabel?.text = hospital[indexPath.row]
cell.detailTextLabel?.text = hospitalDesc[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
myIndex = indexPath.row
performSegue(withIdentifier: "segue", sender: self)
}
}
class PhoneBookDetail: UIViewController{
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var descLabel: UILabel!
@IBOutlet weak var myImageView: UIImageView!
@IBOutlet weak var callHospital: UIButton!
let phoneVA = "tel://5412175034"
override func viewDidLoad() {
super.viewDidLoad()
titleLabel.text = hospital[myIndex]
descLabel.text = hospitalDesc[myIndex]
myImageView.image = UIImage(named: hospital[myIndex] + ".jpg")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}