How to change the segue type of the storyboards - xcode

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)

Related

Need help to write different if statement

(I am) new in the Xcode.
I am making this app, and first I had 3 viewcontrollers; each used to talk with each other with a button: from the first you click a button that goes to the second, and go on. The thing is: I put some switchs in the first viewcontroller and they execute a segue for the second viewcontroller, changing a label. The first viewcontroller has 2 buttons - one of them is part of the segue of the switchs, and the other is for the third viewcontroller. Now my problem: when I click the second button on the first viewcontroller it works just fine, but if click the swicth but not the button of the segue, instead the second button the app crashes.
this is the line of my segue:
if switch1?.isOn == true
{
let secondController = segue.destination as! SecondViewController
secondController.myString1 = "blabla"; ()
As I said: it doesn't interfere in the normal use of the app, but if I click the switch, but not click the button for the segue, instead click the button for the third viewcontroller, the app crashes.
Could not cast value of type 'app2.ViewController' (0x103879548) to 'app2.SecondViewController' (0x1038793a0).
2020-02-25 20:43:39.507421+0000 app2[18433:249963] Could not cast value of type 'app2.ViewController' (0x103879548) to 'app2.SecondViewController' (0x1038793a0).
I need a way to write a condition that if other button is click other than the one of the segue, the switchs should be off.
Any help would be highly appreciated.
This error message you're getting means that segue.destination is not of type SecondViewController and in fact it appears to be of type ViewController. More than likely what this means is you have to go into your Storyboard and more closely examine:
Your segue to see if its destination is in fact of type SecondViewController
The Custom Class part of the storyboard Identity Inspector to make sure you picked a Class and Module for the view controller in question
The above answer is all pretty much in this post, plus some more context/details

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)

Xamarin.iOS: how to add a NavigationBar to a View

I work on a Xamarin native app, where I show a modal view containing a list of countries.
I would like to know if there is a way to add a Navigation Bar to this view through the Controller?
Of course, the Navigation Bar will not contain the back arrow button, but a Title and a right button allowing to close this view.
Thanks for your suggestions.
The modal you present needs be wrapped in a UINavigationController rather than only being a UIViewController. This will give you a NavigationBar.
var modalViewControler = new MyModalViewController(); // UIViewController
var navigationController = new UINavigationController(modalViewController);

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

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.

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