Xcode how to change which viewController loads first at start-up - xcode

I am using storyboards, xcode 4.6.1. I have created an app, but now I want to go back and add a new view controller to the beginning. How do I assign this view controller to be the first one to load up at run-time?

Choose your viewcontroller in storyboard , click show the attributes inspector
and choose initial scene: is initial view controller

Initial View Controller
Initial View controller allows you to initiate storyboard without Storyboard ID
let storyboard = UIStoryboard(name: String(describing: SomeViewController.self), bundle: nil)
let initialViewController = storyboard.instantiateInitialViewController()
Xcode 10.3
Storyboard -> View Controller
Show Inspectors -> Show the Attributes inspector -> Is Initial View Controller
It will update the Initial view controller in the same .storyboard.

Related

How to change the segue type of the storyboards

I've got this problem. I want the view controller to change when the player presses a specific button.
So I added a new "view controller" in the main storyboard, I customised it and then, holding the right button of the mouse, I dragged the button on the new view controller.
It appeared a little menu with different items:
show
show detail
present modally
present as a popover
custom
I've tried all of them, nothing changed (except for the last one: the app crashes).
The new view controller is like a moving window, if you swipe down you go back to the start menu.
What I want is that the new window replaces the first one.
Here's the problem
As you can see, the brown window is movable
As I understand you need to present view controller full screen.
You need to select "present modally" segue type. Then select segue in storyboard
And then select presentation style "Full screen"
Or you can make this programmatically:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nextVC = storyboard.instantiateViewController(withIdentifier: "nextVC") as! NextVCClass
nextVC.modalPresentationStyle = .fullScreen
self.present(nextVC, animated: true)

Cocoa - Present NSViewController programmatically LIKE "Show option" in storyboard (Without being a Modal)

I am trying to present an NSViewController and there are 3 API's available.
presentAsModalWindow()
presentAsSheet()
present(....) for popover
But I want to simply present without the ViewController to become modal.
I found that in storyboard there is an option "Show". If you connect with any action then it will present the view controller and it will not be modal. But in code, I am not able to find a similar option.
NOTE: I want it should present exactly like how it did with presentAsModal without NewController being a Modal.
I found the solution. We need to create a new window and embedd in new Window controller.
let vc = MyViewController()
let myWindow = NSWindow(contentViewController: vc)
myWindow.makeKeyAndOrderFront(self)
let windowVC = NSWindowController(window: myWindow)
windowVC.showWindow(self)

CustomViewController's view's layout becomes wrong when added as subview

I have created a CustomViewController and layed it out in interface builder. Then I am all set to use the CustomViewController's view as a subview in another viewcontroller but when I add it to the other viewcontroller the layout of the custom uivewcontroller becomes wrong.
What can cause this? What is the propper way to do this?
The whole project can be found here https://github.com/agustr/STHLMPubCrawl just download and run (in an iphone 5 simulator). If there is any question about how it should look you can just move the initial view pointer to the 'place view controller cene'
this is the code:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("GPPlaceViewController") as? GPPlaceViewController
if vc != nil{
vc?.view.layer.borderWidth = 4
vc?.view.layer.borderColor = UIColor.redColor().CGColor
self.GPPlaceView.layer.borderColor = UIColor.yellowColor().CGColor
self.GPPlaceView.layer.borderWidth = 2
vc?.view.frame.size = self.GPPlaceView.frame.size
self.GPPlaceView.addSubview(vc!.view)
}
else {
print("could not load GPPlacePageViewController from storyboard")
}
Any help is welcome.
I am unsure if this method of adding a VC's view to another view is wrong or outdated but I seem to remember it working at some point. I contacted apple and they told me to use a ContainerView. It is supposedly explained in detail in this talk 'Implementing UIViewController Containment' https://developer.apple.com/videos/wwdc/2011/.
The biggest problem I had when using the containment View was that you can not drag the segue in interface builder but you have to right click or controll click to point the segue to the appropriate place. Then you can treat that segue as any other in your parent viewcontroller that is to say the viewcontroller that contains the container view.

How to connect storyboard to viewcontroller

In the new xcode 5 how do in interface builder you use to have a drop down menu there to connect your storyboard viewcontrollers to your classes how is this done now?
Unless I'm misunderstanding what you're asking, it's still there. Here are the steps to assign a custom view controller class to your view controller:
Choose your view controller in the list of scenes on the left side.
Choose the Identify Inspector on the right side.
Choose the custom view controller class from the Class list.
1、manual creating a Cocoa Class to the project
2、open the story board, draw a view controller from tool box to the storyborad
3、click the controller you draw into the storyboard, and specify the 'Customer Class' to the class you create in step 1
4、if you use XIB, nibName could be the controller name, else if you use StoryBoard, you need set a storyboard id for your controller in your storyboard panel, and you can use the id and the storyboard in your superController when you want to new a controller
// XIB
var viewController = UIViewController(nibName: "ViewController", bundle: nil)
// StoryBoard
var viewController = storyboard.instantiateViewController(withIdentifier: "The-Storyboard-ID-You-Set") as! ViewController

Standard Back Button in XCode (XIB)

I can't get the standard back button of iOS into a navigationBar because I can't find it in the Object Library, so can I do it with code or something else?
I just want the normal, standard, blue back button - you know which I mean.
To "automatically" have a back button you need first have a UINavigationController. Then you need to take a different UIViewController and add it as the root view controller in UINavigationController's init method:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:someOtherViewController];
Be sure to also set a title for someOtherViewController, usually in it's viewDidLoad or initializer. I'll tell you why this is important in a second:
self.title = #"Some other VC";
Then take a second UIViewController and push it onto your navigation controller:
[navigationController pushViewController:anotherViewController animated:YES];
You now have two UIViewControllers on your navigation stack: someOtherViewController and anotherViewController.
Your view will now have a back button with "Some other VC" in it. This is the title of the view controller that was just moved out of view:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
http://simplecode.me/2011/09/04/an-introduction-to-uinavigationcontroller/
I would also suggest reading up on how UINavigationControllers work and searching this site a bit more for customizing the back button. There are plenty of threads about it.
You can't add the back button yourself. The back button is part of the Navigation controller. If you embed a Navigation controller into your view(s), the back button will appear and be populated by the name of the previous view.
If you're using storyboards select your view controller, then in top menu choose "editor" -> "embed in" -> "navigation controller".
Edit: Here is an exmaple.
I'm running Xcode 7.2. This was driving me crazy, but I figured it out. Here are all the pieces you need to make the Back button appear (make a test project to prove it):
1) You have to have a Navigation Controller and it has to be set to be the initial view controller. So add the Navigation Controller, you will import two tables. Click on the Navigation Controller and on the properties list, check the box that reads "Is Initial View Controller". You will now see and arrow pointing to this view.
2) In our case we want a ViewController and not the included / connected TableViewController, so delete the TableViewController (RootController) and add a new ViewController.
3) Connect the Navigation Controller to the new ViewController by clicking on the top bar of the Navigation controller and orange circle with the arrow pointing left. Hold the Control button on your keyboard down and click and drag from the orange circle to the ViewController and let go. When given the list of options on how to connect the two views, select 'root view controller'.
Done! Now you the functioning navigation bar and you automatically get the back arrow on all segues added. Test this. Add another ViewController and connect to it with a button on the existing ViewController. Use the Control-click-drag approach from the button to the newest ViewController. Select the 'show' option for the new segue you created.
Run it. You'll see the back option has automatically appeared when you click the button and moved to the newest ViewController.
This is all provided by the Navigation Controller, but only when you make another controller the RootController. Happy navigating!

Resources