I have a problem with implementing a button which should redirect my current view to another view when tapping on it.
I have a central view and I already implement the gestures on top, left and right to move to others views.
But on this central view I want to add a button that allows me to redirect towards my right screen without using gesture from right to left with my finger.
I added an IBOutlet action for this button, but I do not know what method to implement for switching back to my right screen (not the top or left screen).
If anyone can help me thank you very much!
If you create a segue in Interface Builder and give it an identifier. You can then perform this segue (what you call "a transition") by calling
performSegue(withIdentifier: <String>, sender: self)
Of course you will need to replace <String> with your segue's identifier
One can create a segue by control dragging from one view controller to another view controller
One can give a segue an identifier by
clicking on the just created segue (this is a line between the view cotrollers in the storyboard)
opening the Attributes Inspector (press: altcmd4 or click on: View > Utilities > Show Attributes Inspector)
filling in the textfield next to the label "Identifier"
Related
I am little confused with the way that segue is working in my app.
I have TabBarController and my ViewController inside it is embedded in NavigationController.
I added identifier to segue "mySegue". So when i perform some action inside my ViewController I run
performSegue(withIdentifier: "mySegue", sender: self)
So segue is performed but I have some things that I don't understand.
View is presented without tab bar and navigation bar. Why? I thought that they should be visible by default.
I want segue to be animated - so view will be presented from right to left and also I will be able to unwind it (simply go back by swiping). But swipe back is not working and view is presented from bottom to top. Why is it?
You should set the segue's type to Push - that way the navigagtion controller will issue the hierarchy and it will actually get pushed to its stack, hence the name.
If you want your segue to transits horizontally, you need to use (Show e.g push) for the segue, like this. It has swipe back by default
As it was not the first time when I meet this problem - I need to point where the problem was. Maybe it will help others when it seems that everything in segue is made right way but it is not working the way it should.
In my case - it was because segue was created in interface builder by dragging not from the ViewController's yellow circle to second ViewController. Segue was created from one of subviews or even TableView / TableViewCell inside ViewController. So in that case it wasn't creating segue in NavigationController.
The best way that I can describe it is through and image, so i drew it out HERE. So, what happens is that in my table view, I press a button to add/edit information. When i am done, I press "Finish" at the bottom, which performs a simple segue back to the table view.
The Problem: Once back in the table view, the "back" button will now take me to the edit info page(which I just left) rather than the VC that came before it.
Is there any way to remove the Add/Edit info VC so that when I press "+" and "Finish" The back button will ignore the Add/Edit page?
Thank you for your help.
EDIT: . As you can see, when you press a button on the Table VC (lefT) it will take you to the right VC. Then, when you press finish at the bottom, it will perform a segue(no code, just a control-drag segue). The problem is still that the text message VC's back button will now direct back to the right VC, rather than the one preceding it (left)
I suppose you have a UITableView inside a UINavigationController since you have a back button, so:
User Tap Edit button: Push EditViewController in your UINavigationController
User Tap Finish from EditViewController: Save data, pop manually EditViewController and call reloadData of your UITableView
You would have to embed your complete sequence of view controllers in the navigation controller. This would maintain a stack of all the views that you would segue to. It will also give you a bcak button to go back to previous view. Alternatively, you can call the method popViewController() on navigation controller object to programmatically go to previous view. I hope that helps.
I just started with Xcode and Swift.
I try to build my first little App for iOS. But now I have the problem, that I don't know how to implement a the back button, so that i come back to the view before.
My Storyboard look like this:
When I open the A-Z view, I want to display the Back Arrow, which turn me back to the Item 2 view.
To open the A - Z view I connect the button "Medikamente A - Z" with the Navigation Controller.
When using storyboards the back button is usually implemented with unwind segue.
I usually like to follow raywenderlich toturials on UI related topics, like this - http://www.raywenderlich.com/113394/storyboards-tutorial-in-ios-9-part-2
It include a detailed example of how to implement back button in storyboards. Quoting from it -
Storyboards provide the ability to ‘go back’ with something called an unwind segue, which you’ll implement next.
There are three main steps:
1. Create an object for the user to select, usually a button.
2. Create an unwind method in the controller that you want to return to.
3. Hook up the method and the object in the storyboard.
When using UINavigationController, whenever you push to a new ViewController the back button will automatically appear, so you can jump back to the previous View Controller.
So it's works like:
UIViewController -> UIViewController -> UIViewController
A back button will appear on the last 2 so you can pop back the the previous ViewController.
You don't have to do any additional coding for the back button to appear, it'll do it on its own. I hope this clears it up. Let me know if you have any questions.
To implement a back button, your root view controller has to be a Navigation Controller.
The first view controller becomes the navigation root of the navigation controller.
If you want to present another view controller, you select a "Show Detail" relationship as the action for the button which should show the view controller. To do this, Ctrl-click and drag from the button to the destination view controller and select "Show Detail".
I had the same problem, even when on the storyboard the back button was visible at design time.
I deleted the segue, and recreated it with "Show" instead of "Show detail". Changing the segue to "Show" had no effect. I think this is a bug, so if you miss that back button delete and recreate the segue.
In main view controller there is an ImageView in the middle, UIButton in the bottom. The ImageView has tap gesture and when you tap it the image changes from Credits to Scenes images and the Button title changes to Credits Button from Scenes Button. Those buttons must have segues to its own. So I want to create segues to CreditsController and ScenesController from that button. I couldn't create double segue from the storyboard.
I appreciate for any help and I can provide more information if necessary.
Thanks.
You can do "double segues" from a storyboard. There are two methods:
Ctrl-drag from the view controller symbol (the yellow one) to the destination view controller. Name the segue and call it (in the button handler or the gesture recognizer handler) with performSegueWithIdentifier.
Use separate buttons with title or image and set their hidden property as appropriate. Now you can ctrl-drag from the buttons to the destination view controller.
I have a UIScrollView with my View, but I can't seem to create a seque push from this over to another controller.
I have successfully created a Seque from a UICollectionViewCell over to my destination controller but when I try and create one from the UIScrollView (in the StoryBoard) the blue connector will not see the destination controller as an option to create a segue too.
Any pointers would be much appreciated.
A push segue is only meant to be used with any type of button (ex. UIButton, UIBarButtonItem) or cell (UITableViewCell). Push segues are used to show another view controller over the current one. UIScrollView is only meant to scroll the content on the current view controller, just in case the content of the view controller exceed the screen size. I suggest you look at the Apple UIScrollView Class Reference page here to get a better understanding of UIScrollView
Push segues don't have to be connected from individual views like UIButtons or UITableViewCells. This is too limiting, because a button (for instance) can only connect to one segue. Try connecting them from the view controller itself, then you will be able to do as many as needed. I open the Document Outline, and drag from the View Controller at the top of the scene (the item having the yellow circle icon next to it) to the view controller on the Storyboard that I want to connect to.