Stack Overflow Asked by Karen Cruz on December 27, 2020
I’m trying to develop an App that can track some Information from elements of an Array.
like:
array = ["Anna", "Charles", "Simon", "Criss"].
I’ve created a UITable View and I want to be able, when I click on the Name, to open a new View and fill following Information.
Adress:
Age:
Hobbies:
I am new in Swift and I don’t know how to create this View.
Thank you for your help!
On tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
you can open UIAlertController
and get thoese information.
For example, you have an Array
let dataArray = ["Anna", "Charles", "Simon", "Criss"]
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alertController = UIAlertController(title: "Give title here", message: "", preferredStyle: .alert)
alertController.addTextField { (textField : UITextField!) -> Void in
textField.placeholder = "Enter Name"
textField.text = self.dataArray[indexPath.row]
}
alertController.addTextField { (textField : UITextField!) -> Void in
textField.placeholder = "Enter Address"
}
alertController.addTextField { (textField : UITextField!) -> Void in
textField.placeholder = "Enter Age"
}
alertController.addTextField { (textField : UITextField!) -> Void in
textField.placeholder = "Enter Hobbies"
}
let saveAction = UIAlertAction(title: "Save", style: .default, handler: { alert -> Void in
// TODO:- You will get that informaton here
let first = alertController.textFields![0] as UITextField
let second = alertController.textFields![1] as UITextField
let third = alertController.textFields![2] as UITextField
let fourth = alertController.textFields![3] as UITextField
})
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil )
alertController.addAction(saveAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}
When you will click on save
you will get that information in the closures.
Correct answer by Rashid Latif on December 27, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP