Can't create Segue from UIScrollView - ios

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.

Related

Xcode Storyboard: Can't add View to ViewController

I'm using Xcode 10 (with Swift 5 and for iOS 12) and my app is currently set up like this:
UIViewController 1 (login screen) - segue12 to ->
NavigationController that automatically created
UIViewController 2 with a UITableView - segue23 to ->
UIViewController 3 (detailed info about an item in the UITableView with automatically created "back" button)
The NavigationBar only contains a " ".
I now want to add another UIView with a button below the UITableView but Xcode won't let me drag it below the UITableView, only either into the UITableView or directly underneath "First Responder", which puts the View outside into its own window.
If I delete "My Table View", it won't let me drag in a replacement either.
How do I fix this, so I can add the new UIView + UIButton?
NavigationController that automatically created UIViewController 2
That explains everything. When you drag a navigation controller into the storyboard, what you get is a navigation controller and its root view controller, and the root view controller is a UITableViewController.
Let's step back for a moment. A view controller can and must have exactly one main view. It occupies the whole scene. It cannot be resized. It cannot have a sibling view, because it has no superview for a sibling view to be a child of. It can only have children (subviews).
Well, in this case, ViewController2 is a UITableViewController, and MyTableView is ViewController2’s main view. (A table view controller is always configured this way, and that is what you got when you dragged the navigation controller into the storyboard.) That is why you cannot add more views to it, except as subviews, e.g. prototype cell contents. Your button has no place to go except inside the table view.
So, what to do?
If the extra interface you want to add is just a button, the usual solution is to put it into the navigation bar. It becomes part of the table view controller's navigation item.
If you don't want to do that — that is, if you really want the button and the table view to be siblings of one another in the interface — then you need to replace ViewController2 itself with an ordinary view controller. Now its main view will be an ordinary view, and you can drag anything you like into it, including a table view and a button. More likely, instead of a bare table view, you would use a container view, with an embed segue to a table view controller.

Swift: Storyboard solution to clicking from ViewControllers to ViewController in a ContainerView

I am building a App with a fixed Top Bar and some fixed Buttons at the bottom. In the middle of my MainViewController I want to have some Tables I switch in between. The ways I want to do it:
clicking the buttons at the bottom
clicking buttons in my tables
To solve the problem I put a ContainerView inside my MainViewController. It works for me already to switch the InsideViewControllers by clicking one of the buttons at the bottom. I solved it with Apples Tutorial programmatically. By click on a button I change The childViewController of my ContainerView.
When clicking a button in my InsideViewController I am sending a message to my ParentViewController (the Container) right now. This I did by implementing a protocol and checking if my parentViewController implements it.
Now my question is if this is the optimal solution to click from ViewController to ViewController inside my ContainerView. Or is there a better way to click a button on my Table and get the next Table?
What I was thinking about is maybe possible:
A storyboard solution. I want to connect ViewControllers inside my storyboard. So that I have a button on my first view Controller and do a segue from this one to the next ViewController. If I do it just like explained the new ViewController is not filling the Container. There pops up a normal ViewController to my app. Here a example View of this idea:
Is it possible or do I continue by sending messages to my parent?
Sure you can. You can start reading Implementing a Container View Controller, specifically, the section "Configuring a Container in Interface Builder". At the initial phase of adding the Container View, you will automatically see a new UIViewController appearing there. I guess if you will want to perform transitions, you will have to Embed In a navigation controller that new view controller.

Pushing a ViewController Through a UIScrollView

I have a custom uiscrollview class that has certain views and buttons. When I press a button in this custom scrollview, I want to present a new viewcontroller. Since this scroll view is inside of a view controller, and the custom class doesn't have the authority to push view controllers like a navigation controller, how do I push a new view controller through this uiscrollview class without throwing an error? Whenever I create a new navigationcontroller and an instance of the viewcontroller that I want inside of the method for when the button is pressed, and I present that viewcontroller, I get an error. Also, all of this is programatic and dynamic, not though storyboard. Thanks.
The scrollView must be inside a viewController.
The best way to accomplish your scenario is to put the viewController that contains the scroller inside a navigationController, Then you can push to wharever you want.
Hope this may help
You can try to instantiate viewController through the storyboard, or directly from class, after that present it as a modal view controller from your source UIViewController like this
presentViewController:animated:
This possible leads to animation issues, that could be solved implementing your own animation

Storyboard: can't drag view to viewcontroller

I'm new to iOS, I'm following this tutorial: http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/. I just drag and dropped a Page View Controller to the storyboard, and tried to drag an Image View into it, but it bounce back, what am I missing?
When manipulating the content of ViewControllers in storyboards, the zoomlevel must be set to 100%. You might want to check this (simply doubleclick on the ViewController).
UIPageViewController is a container view controller, so you can't put individual views in one in Interface Builder. You need to create one or more individual content view controllers and control-drag from the page view controller to the page content controller and then put actual content in the page content controller.
Walk through the tutorial again, but this time note the references to "page content view controller"

Load view into navigation view controller when table cell is pressed

I have an iOS app which is using storyboard (and ARC for that matter). Now in that app i have a tab view, where one of the tabs leads to a table view found within a UINavigationController. Up to this point, loading views was 100% handled by segues in the storyboard. Now in the table view, I have some cells which I create programatically, and i want them to lead to a different view (which will also be in the UINavigationController). Now they always lead to the SAME view, just pass different information when pressed (that i have already taken care of). The thing is, I can't menage to do it in the storyboard, because the cells are created programatically...
So is there a way to do this using storyboard? If not, how may I accomplish this programatically?
A picture is attached to make the organisation of the storyboard clearer.
Thankyou for any support!
Create a push-style segue in the storyboard between the two controllers and give it a name. When the user selects a cell, use performSegueWithIdentifier:sender: to trigger the transition.

Resources