Reputation: 180
I have created a segue from view controller A (Task View Controller) to view controller B (Add Task View Controller) that is triggered through a button(add) in view controller A.
I have a problem: If I want create a task in more detail, I will tap on button to show View Controller B, then tap save on View Controller B to done!
But when I want to create a task quickly by text in UITextField
beside button add. Then tap on Button and the task was created without present View Controller B.
this is my story board with connection inspector: connection
i try to add if statement (in comment code) but not working
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let identifier = segue.identifier else {return}
switch identifier {
case Segue.addTaskVC:
// if let taskTitle = inputTF.text, !taskTitle.isEmpty {
// // Create Task
// let task = Task(context: coreDataManager.managedObjectContext)
//
// // Configure Task
// task.updatedAt = Date()
// task.createdAt = Date()
// task.title = taskTitle
//
// updateView()
// return
// }
guard let destionation = segue.destination as? AddTaskVC else {return}
// Configure Context
destionation.managedObjectContext = coreDataManager.managedObjectContext
default:
break
}
}
this is my action is conected with segue
@IBAction func addTaskButtonWasPressed(_ sender: Any) {
print("add Task Button Was Pressed")
// **Save quickly here**
}
is there a way to save quickly and prevent striggering segue?
Upvotes: 0
Views: 46
Reputation: 285072
shouldPerformSegue(withIdentifier:sender:)
false
if there is text in the text fieldaddTaskButtonWasPressed
check also if there is text in the text field. If yes, save the task.Upvotes: 1