Capture Storyboard Segue from application menu - swift

Is there a way to capture a segue generated from the menu in Application Scene? My searches have not been forthcoming.
I have a Preferences menu item that is under the App name like most other Apple macOS applications, but unlike other segues, that segue is not firing the prepare or shouldPerformSegue methods.
I want to trap the segue like I do with other segues when they fire the above mentioned methods.

A reliable way is:
Connect the segue from the main view controller to the Preferences controller.
In the main view controller create an IBAction. In the action call performSegue
Connect the menu item to the First Responder of the application scene (red cube). Select the IBAction.

Related

How to call custom function when closing popup window in OSX Cocoa Application using Swift?

I have two ViewControllers and a button which is drag-and-dropped from the first ViewController (source) to the second one (destination, popover). This connection is set as Popover Storyboard Segue.
How can I call a specific function in the source ViewController when the destination ViewController (popover) is being closed (clicked outside the popover)? Is there any standard view lifecycle method like viewWillAppear etc. for this?
If you set the NSPopover delegate to the source ViewController, then you get methods such as popoverWillClose: and popoverDidClose:.
There's also corresponding notifications (as standard with macOS controls), if you do not like using the delegate.

Trying to change views after button is pressed

I'm trying to execute code when a button is pressed for an application but I can't find how to change the views after the code is executed. Is there a way to switch views how I want to or is there another way? Thank you in advanced, I'm very new to xcode.
edit: I'm trying to go from one view to another, not the view controller and yes I have one storyboard that I planned on using for the whole project if possible.
To execute code when a button is pressed, you have to set up a method that the button is hooked into. Because you said you're using storyboards, I'll assume your button is on the storyboard. Go to the assistant editor, hold ctrl, and click-and-drag from the button to the view controller's .m file (#implementation section). This will create an IBAction method, and any code in this method will execute whenever you press the button.
The method will look like this:
- (IBAction)aButtonPress:(id)sender {
}
According to your comments, you say you only want to change the on-screen view, and not transition from one view to the next.
Views are added and removed with the following methods:
[aSuperview addSubview:aSubview];
[aSubview removeFromSuperview];
I can't really tell you much else with a lot more detail from you... and even though I asked twice in the comments and you said you only want to change the view, not the view controller... I think you probably need to transition to a new view controller. Impossible to know for sure as you've given almost no detail...
But if you want to transition between view controllers (which also transitions views), then ...
Create two view controllers on the storyboard. Hook them together with a segue, and give that segue a name. Now, to perform that segue in code:
[self performSegueWithIdentifier:#"YOUR_SEGUE_NAME" sender:self];

Segue to Tab Bar Controller with performSegueWithIdentifier

I'm learning iOS and I'm working on what amounts to a Proof of Concept app in XCode 4.2. I essentially want to allow a user to enter a user/pass combo and if the user is in an array of objects, pass them on to the "Content" view, but if not, pass them on to the "Register" view.
In either case, since the app itself will be a tabbed app (though the login and register views are not tabbed), I need to be able to segue from a typical ViewController to a TabViewController.
- (void)logIn:(id)sender{
[self performSegueWithIdentifier:#"Content" sender:sender];
}
Currently, I have the app segueing to the proper ViewController, which is a TabBarController embedded in a NavViewController...but once it gets there...there are no tabs!!
What am I doing wrong?
Now you aren't loading TabBarController that's why you don't have any tabs.
What I suggest you:
In Log In ViewController you can also add "register" button, and place a segue from it to Register View Controller.
Add IBAction from log in button, which will check for log in and pass, and if it's OK load Content ViewController or TabBar Controller with Content ViewController.
I strongly recommend you to study iOS5 storyboard tutorials to get to know how the view controllers interacts.

Storyboard iOS5 - How to prevent the storyboard changing when pressing the Segue button

I've created an app using the new iOS 5 Utility app template. Since the previous SDK, we now have to use storyboards for the GUI (which I do like using) but I am wondering how to prevent the "Segue" from flipping the view to the next view on the storyboard.
By default there is a button which when pressed flips to the "FlipsideViewController" and I would like to use this button as part of a login form but I need to stop the storyboard going to the Segue unless the credentials are correct. I have all my login code written but cannot prevent the page from flipping. The method I thought would do this actually prevents the user from going back by clicking the default "Done" button on the "FlipsideViewController".
Can anyone help?
You have to connect the button to an IBAction instead of a segue. In the action, check if the credentials are correct, then call performSegue: to perform it.
You will have to connect the segue directly from the view controller to the next scene instead of from the button.

iOS 5 - add Splash/Launch view with storyboard

i create project with storyboard base uitabbarcontroller,
i try to add splash view that will show until server request will finsih,
so i create a new view controller class called "SplashViewControler" with xib file
and i try to add as subview to windows object.
the SplashViewControler not show...
any ideas how to Implement splash view with storyboard ?
thanks
I'd add that SplashViewControler to your story board. Then, using the story board designer, make the SplashViewControler the initial scene by checking off the "Is Initial View Controller" property of your SplashViewControler. Then, create a segue from your SplashViewControler to whatever your next view controller is. Make sure you name that segue. Then, when your server process is complete, fire that segue manually:
[self performSegueWithIdentifier:#"YourSegueName" sender:self];
I may be wrong but I think the HIG talks about not doing splash screens this way. You also need to consider how you will handle a server timeout or error from the server...