I've added a button in my ViewController. This view controller was activated with a modal segue. How can i dismiss this from interface builder. I must to use an IBAction or can do it from interface builder?
Asked
Active
Viewed 615 times
0
-
Use an unwind segue – Paulw11 Nov 01 '18 at 21:26
-
Would you please explain your question a little more – Abhinav Jha Nov 02 '18 at 06:41
-
@AbhinavJha of course. I'have a table view controller with a list of element, this is wrapped by a navigation controller. In this view i have a "+" button in navigation bar for create a new item. I want to open the new item view in modal segue. That's ok. Now in the new view i'have in the navigation bar a cancel button and a save button. I'can't dismiss the segue and close this view. – Kobazzo Nov 02 '18 at 08:42
-
@Kobazzo, please find my answer below – Abhinav Jha Nov 02 '18 at 14:32
2 Answers
0
Try using the below code
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(self.leftNavigationItemAction(_:)))
}
@objc func leftNavigationItemAction(_ sender: UIBarButtonItem) -> Void {
self.dismiss(animated: true, completion: nil)
}

Abhinav Jha
- 295
- 1
- 17
-1
Swift 3:
present(UIViewController(), animated: true, completion: nil)
dismiss(animated: true, completion: nil)
Swift 2.2:
self.presentViewController(true, completion: nil)
Hide/dismiss a view controller:
self.dismissViewControllerAnimated(true, completion: nil)
hope this will help , Thank you.

Fansad PP
- 459
- 4
- 11