Hi I created a single view project and i put a button in the scene that I embed in navigation bar with a bar button on the right to this scene and then I created the second screen which contain an image view, Then I dragged bar button to second scene using Crtl+Drag and choose show action for segue. which works fine.
Problem : Then I created third scene with some image view in it and I dragged the button from first scene with Crtl+Drag to the third scene and choose "show" for segue action.
but when I run the app only navigation bar segue works and the button do nothing.
UPDATE :
I found why this problem occurs, it's because of stack view constrains. when i put a button or image view in stack view and give it constrain it won't work. but why ?
any suggestion?
As per the discussion, your first problems were solved by setting UserInteractionEnabled to true on the UIImageView, and as for the buttons, it seems they were set up incorrectly the first time.
Related
I am new in iOS development and in Swift. I have a question. I added in one of the ViewController NavigationController. But I have some problems with back button cause it doesn't appear on other Views. I tried with self.pushViewController() and with self.present() but it doesn't work. If I mark in NavigationController Is Initial View Controller then everything is fine but I don't want it because then app starts with this screen(where I have NavigationController).
Please help me, what I should to add or to write?
This is an image of my storyboard
And this is what I have if I run and go to another ViewController, as you can see I don't have navigation bar and back button.
You got 2 options :
1) Add a navigation controller in the root ViewController, Hide throughout except the last one. Make sure you push the last VC so Back option will be there by default
self.navigationController.pushToViewController(BarCodeViewController)
2) Use a custom View on top of last viewController add a custom button to that view. But this time present it from previous ViewController
self.present(BarCodeViewController)
when back button clicked dismiss it by adding target to the button. self.dismiss()
I have a View Controller with one main image covering the whole of the view, and a few buttons. When I get to this view through a push segue from the previous controller, the view is shifted downwards below the status bar, showing a black strip where the view is missing (and moving my buttons out of position).
When I show the next screen and dismiss it, the view shifts back to the correct position.
How can I make sure that the correct distribution of the view (second image) happens every time?
UPDATE:
This is how my storyboard looks:
I was able to fix this problem with a simple line of code:
self.automaticallyAdjustsScrollViewInsets = false
By the way, this was happening to me on a UIPageViewController and this line of code was included in ViewDidLoad of that VC, not the Content View Controller.
In the current version of Xcode a few things seems to work a bit different.
I have a little problem working with a simple navigation. This is what I do:
I have a Storyboard with two scenes.
I connect the scenes with a segue of type "Show".
(In the past I did use "Push" but that is deprecated now.)
I select the first scene and choose "Embed in Navigation Controller.
Now both scenes will get a gray bar at the top but only the first scene will also get a Navigation Item.
Only for the first scene I am able to edit a title attribute and only for the first scene I am able to add a Bar Button.
Navigation itself works fine. The title of the first scene is the text of the Back-button in the second scene.
Why has the second scene no Navigation Item?
Is it because of the segue type?
Yeah, its a bug in Xcode from version 6. If you want Navigation Item in second view controller too, then there is a hack to get it.
Change the seque type from show to push. Now Navigation Item will appear in second VC too. You can again change the seque type from push to show, the Navigation Item will still present in second VC.
IB will automatically add UINavigationItem to root view controller of your UINavigationController.
To the rest of your controllers in navigation flow you need to add UINavigationItem manually from IB Object library.
What I do is to drag a navigation item from the list of controls to the top, gray bar on the second ViewController. Then you can drag other items such as bar buttons onto it, as well as being able to edit the title.
My app has two scenes: a UIViewController with a navigation bar at the top, and a UITableViewController. If I wire up a button in the first scene to segue to the table view, everything looks great. However, if I wire up a tap gesture in the first scene to segue to the table view, then the navigation bar doesn't display in the second scene in Xcode. When the app is run, the navigation bar appears as it should, but in the storyboard editor it is gone.
Is there something special that needs to be done to preserve the navigation bar when segueing from one scene to another using a tap gesture? To implement the tap gesture, I dragged it onto one of the elements in my storyboard, then control dragged from the "tap gesture recognizer" icon at the bottom of the scene to the scene I wanted it to segue to. Then selected "push" for the segue type.
I never noticed this before, but I do see the same thing. This seems like a bug to me, but maybe Apple has a reason for doing this. You can go to the "Simulated Metrics" for your controller, and set the "Top Bar" to be a navigation bar, which will allow you to set the title and add a bar button item if you want.
I have an existing ios5/xcode 4.2 app, and I want a button to open a view that will display a list of items, and have a back button and an add new button.
I thought I could achieve this by adding a button to the main view controller, then dragging in to the storyboard a new UITableViewController, then embed a UINavigationController (editor->Embed In->Navigation Controller).
Then i right clicked on the button, dragged it to the navigation controller, and thought, ok this should work.
However, there is no back button, and xcode will not let me drag one in, nor will it allow me to drag in the button bar item "[+]" for the link to add new.
When I run the app, the list shows, of course I have no way to go back to the view controller with the button on it.
What am i doing wrong? - thanks.
(my question is similar to this
but for xcode 4.2)
Embed the main view controller, not the new one, in a UINavigationController. This should add a simulated UINavigationBar to the main view (if not, set one up under Simulated Metrics). At this point you should be able to drop in a UIBarButtonItem to the main view's simulated bar.
Next, draw a connection from your button to the new UITableViewController to set up a push segue. At runtime, the back button will appear in the bar automatically.
Make sure when you try and drag the items into your view controller that the storyboard is zoomed in. XCode won't let you add items if you are zoomed out.