Long Vu
Long Vu

Reputation: 180

How to perform action and not striggering segue?

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

Answers (1)

vadian
vadian

Reputation: 285072

Upvotes: 1

Related Questions