我是iOS开发的新手,但是取得了进步。对我来说,编程有点太多了。
// Code in alert
let alertController = UIAlertController(title: "Action Taken", message: scan.stringValue, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: {(alert: UIAlertAction!) in gotoTableView()}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler:nil))
present(alertController, animated: true, completion: nil)
func gotoTableView () {
let Employee1TableViewController = self.storyboard?.instantiateViewController(withIdentifier: "viewFromScanner")
// the code below helped add searchbar to the table view. Witout this, the tableview didn't have search capability
self.navigationController!.pushViewController(Employee1TableViewController!, animated: true)
}
// Code in tableview that the alert calls, which in turn cals a Segue to detail screen
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showDetail", sender: indexPath)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let rowSelected = (sender as! IndexPath).row
if let destinationVC = segue.destination as? EmpViewController {
destinationVC.empIdText = getSwiftArrayFromPlist()[rowSelected]["empid"]
destinationVC.firstNameText = getSwiftArrayFromPlist()[rowSelected]["firstname"]
destinationVC.lastNameText = getSwiftArrayFromPlist()[rowSelected]["lastname"]
// code goes on further to list other employee details
您可以尝试为此设置一个bool
var currentCaller:Bool?
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let rowSelected = (sender as! IndexPath).row
if let destinationVC = segue.destination as? EmpViewController {
destinationVC.empIdText = getSwiftArrayFromPlist()[rowSelected]
destinationVC.calledFromAlert = self.currentCaller
}
}
要么
let Employee1TableViewController = self.storyboard?.instantiateViewController(withIdentifier: "viewFromScanner") as! Employee1TableViewController
Employee1TableViewController.calledFromAlert = true
否则默认为false
class Employee1TableViewController:TableViewController
{
var calledFromAlert:Bool
}