Reputation: 378
I would like to a let user create a folder in my app. More specifically, when the user presses "add folder" button, I would like to have the following text field to pop up
How can I implement it?
Upvotes: 2
Views: 5762
Reputation: 4935
For custom PopUp:
By Storyboard
Step 1: Create a UIViewController with this pop up message.
Step 2: Intead of push, Present it from your parent View and set Parent View transition style to cross dissolve.
By Code:
if let nav = self.navigationController
{
UIView.transition(with:nav.view, duration:0.25, options:.transitionCrossDissolve, animations: {
_ = nav.popViewController(animated:false)
}, completion:nil)
}
Upvotes: 2
Reputation: 190
It's going to look something like this:
// create the actual alert controller view that will be the pop-up
let alertController = UIAlertController(title: "New Folder", message: "name this folder", preferredStyle: .alert)
alertController.addTextField { (textField) in
// configure the properties of the text field
textField.placeholder = "Name"
}
// add the buttons/actions to the view controller
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let saveAction = UIAlertAction(title: "Save", style: .default) { _ in
// this code runs when the user hits the "save" button
let inputName = alertController.textFields![0].text
print(inputName)
}
alertController.addAction(cancelAction)
alertController.addAction(saveAction)
present(alertController, animated: true, completion: nil)
Let me know if this helps.
Upvotes: 8