swift Xcode 6 unwind segue action doesn't fire - swift

"Done" button of the modally presented controller ("Modal") is bound to an exit action defined in the primary controller ("Main"):
#IBAction func done(segue:UIStoryboardSegue) {}
"Done" button is not firing!
I have tried the manual segue approach from Unwind Segue in Xcode 6 Beta 4 and bound the "Done" button action to following code in "Modal":
#IBAction func donePressed(sender: AnyObject) {
performSegueWithIdentifier("unwind", sender: self)
}
it doesn't work too!
if I remove tab bar controller everything is working fine - is that a bug or a restriction?
P.S.There is an annoying log output I can't get rid of:
2014-08-17 16:14:15.380 SwiftPhotoCards[9113:497540] 17545849:_UIScreenEdgePanRecognizerEdgeSettings.edgeRegionSize=13.000000
no idea whether it is related to the issue or not but I thought it's worth mentioning it.

I've been struggling with what may be the same issue (although I'm using a Split View instead of a Tab Bar) and was able to resolve it by setting the Modal segue to "Presentation: Current Context" instead of "Default" in the Attributes Inspector:
(This is the setting on the Segue arrow that creates "Main" to "Navigation Controller" in your screenshot).

Related

Making Inspector Sidebar in macOS Window

I would like to make an "inspector sidebar" in a macOS window. You know the inspector in Xcode:
The sidebar's content should be context sensitive. Depending on the user's selection in the main window there should be different dialogs.
Which technologies do I have to use to get this behavior?
My attempts were (in Storyboard):
Insert a Split View into the window.
Insert a Tab View Controller into the right Custom View of the Split View
But this didn't worked: I could easily insert the Split View into the window. And I could easily insert a Tab View Controller to the Storyboard. But I was not able to insert the Tab View Controller into the right view of the Split View.
So how do I achieve the desired behavior?
Finally I solved the issue. I had to add a CustomView to each of the tab's CustomViews. This way, Xcode added ViewControllers automatically. Here are the individual steps:
First, I had to insert a SplitView into the storyboard. Nothing problematic here yet.
Second, I've added a TabView (Style: tabless) into one of the CustomViews:
And third, I needed to add ContainerViews to each of the tabs:
This way Xcode added ViewControllers for each of the tab's ContainerViews:
No I can chose the different Tabs programmatically:
#IBAction func showInspector1(_ sender: NSButton) {
self.tabView.selectTabViewItem(at: 0)
}
#IBAction func showInspector2(_ sender: NSButton) {
self.tabView.selectTabViewItem(at: 1)
}
I would like to thank for the comments, that helped me making progress and solving this issue.

How to detect a click from an NSToolbarItem inside an NSWindowController?

I have a toolbar on my macOS app, developed in Swift. The toolbarItem is dragable onto the NSWindowController, and I can setup an IABAction function, I just have a print in the function at the moment. And when I click on the button nothing happen the click does not seem to be recognised as an action ?
I had a few more line of code in the function but deleted it and now have just the print("test") line.
#IBAction func exportCsvClicked(_ sender: NSToolbarItem) {
print("test") }
No output observed, so I'd love to get "test" in the console when I click on this button.
Here is a list of the connections associated with the toolbarItem.
I found a way to get around the fact that the IBAction from an NSToolbarItem does not recognise the click on this item:
1/I made a customSegue from the item to the main window controller (it can go anywhere)
2/The prepare for segue function posts a notification to the notification saying that the item has been clicked.
3/The main view controller observes the notification and presents, either has a popup or a sheet (I got two buttons), the view that I have setup in the storyboard (referencing with the storyboardID). I found that you need to pass on all the necessary variable to setup the view from the main view Controller, and that there was issue of code in the viewDidLoad function of the sheet/popup view not running, I am suspecting that they might be different instances.

Button ignores action when segued to a previous viewcontroller

So here is my current issue.
I want to unwind to a previous viewcontroller lets call it viewcontroller1.
This works fine, except that the button action
that is hooked up with the segue, also has a lot of other code written in it. However, when pressing the button xcode ignores the code thats already written.
So this is my question how do I make the button perform the written code and then engage the segue??
For the unwind segue I've created an empty action in ViewController1.
#IBAction func unwindtoViewcontroller1(segue: UIStoryboardSegue){}
And hooked ViewController2 up with this segue action (using ViewController2:s exit button).
Ive also set the segue to "revealviewcontrollerpushviewcontroller"
Thanks in advance for all the help I can get I am really stuck.
Best regards Albin
You should be able to do it this way:
Open Assistant Editor, then control drag from the button that performs the unwind segue in ViewController 2 to create an IBAction. That's where all the code for the action you would like your button to do should go.
This action gets performed before the unwind segue function is called.
So your button will do both: action and unwind.
I have made a simple project to illustrate and printed the output to the console. The button in yellowVC performs an action before unwind.
So as you said, in the first ViewController (in my example the green one you have an IBAction for unwind segue
#IBAction func goBackToGreenVC(segue: UIStoryboardSegue) {
print("go back")
}
Then in the second ViewController (in my case the yellow one), control drag from the button to Exit to set unwind segue and then also control drag from the button to Assistant Editor for an IBAction, something like:
#IBAction func goBackToGreenVCButtonTapped(_ sender: UIButton) {
print("performing an action before unwind")
}

Unwind Segue Navigation Bar Button Xcode 8.0 Swift 3.0

I want to create an app in Xcode 8.0 that lets the user press a bar button item in the navigation bar. Once this button has been clicked an unwind segue will take place whilst also printing, "helloWorld" to the output section at the bottom of Xcode. I have successfully created an unwind segue using:
#IBAction func unwindToViewController (sender: UIStoryboardSegue){
}
I then linked this to the bar button item on the navigation bar so that when I tap the bar button item on the navigation bar the view disappears downwards.
I am trying to simply print("helloWorld") onto the output section at the bottom of Xcode when I press the done button but nothing appears on the output section. So far I have:
#IBAction func add(_ sender: AnyObject) {
print("helloWorld")
}
in the View Controller Swift File for that View Controller.
For unwind We need to remember only two points
1) We need to put below method into Destination ViewController.It is a place where we want to navigate to. Here method name can be different but arguments matter a lot.
#IBAction func unwindToDestinationViewController (sender: UIStoryboardSegue){
}
2) Go to the Source viewController from where you want to go back. Now click on unWind button on top right and Control-Click and set outlet to the Back button(Example)
Kindly check this post on stack overflow. This is a duplicate of below post.
You can find the answer in the given below link.
https://stackoverflow.com/a/39916477/2894335
This Blog gives a very nice introduction to unwind segues. article link here.
Try the following tutorial will fix your problem and help you to understand more about how to perform unwind segue...
https://www.andrewcbancroft.com/2015/12/18/working-with-unwind-segues-programmatically-in-swift/#identifier
http://ashishkakkad.com/tag/uistoryboardsegue/
Hope this helps...

Is there a better way to segue back to main menu?

I need several view controllers to segue back to a main menu. After adding the terminal segues, by adding a button and creating a show segue, my storyboard looks like a rats nest of confusion. Is there a better way to link the terminal view controller back to a main menu, or is this how it's done?
After reading up, it looks like this is the best solution for my needs, since there is no data to push from the terminal view controller.
#IBAction func backToMain(sender: AnyObject) {
self.navigationController?.popToRootViewControllerAnimated(true)
}