I'm in trouble with passing from one containerview to another UIViewController
This image below demonstrates a storyboard for what i want to do.
My app has one Containerview and I added button in this app. When I hit the button I want to pass another view via segue. But when I hit to button view is being opened on full screen. I just want to open this view, same size of containerview. Which segue can be useful for this trip? How canit be done?
If you change the viewcontroller that is embedded to a UINavigationController and then make the original embedded viewcontroller the rootviewcontroller of the navigation, then you should get the desired behavior.
set fixed size in attribute Inspector what you want then it will show only that size view
Related
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.
In the interface builder I have a UITabBarController and it is set as the initial view controller. From the tab bar controller, I have linked three independent ViewControllers; two UIViewController's and one UITableViewController. I have embedded all three of these views inside UINavigationController's as each of these views will eventually segue to a new view.
Interface Builder
Problem:
I now want to link one of the UIViewController's to the UITableViewController using a button to segue to the table view. This way I can pass information, i.e. func prepareForSegue(), to the table view. I want to maintain the tab bar controller at the bottom, however I do not want to have the ability to go back to the previous UIViewController from the current UITableViewController via a UIBarButtonItem at the the top of the view; That is what the tab bar at the bottom is for.
However every time I segue "Show" the table view (it is actually a segue to the table views navigation controller), the navigation bars at the top and the bottom of the table view disappear. Is there anyway to prevent this from happening?
I have also tried segue "Show" directly to the table view, in which case the tab bar is visible, but then it displays a "back" button at the top of the view to segue back to the sending UIViewController. I am hesitant about accepting a solution that would just hide the back button, because I feel I will run into problems down the road when I want to navigate to a detail view from the table view itself, since I would be bypassing the UITableViewController's UINavigationController.
Any solutions would be greatly appreciated. I have been trying to solve this problem for hours and I'm about to put my head through my computer screen. Also I thought about just using tabBarController?.selectedIndex on the button click to shift to the table view, and then passing the information using NSUserDefaults, but this is out of the question since I would be passing a custom object, and would have to encode and decode every custom field.
I you use a segue to get to it, as you say, you will still be using the UIViewController's UINavigationController which seems a bit messy. So I actually think selectedIndex is probably the best way to go as once you change to the UITableViewController you'll be in the correct navigation stack.
Instead of using NSUserDefaults, why not just reference the UITableView itself from the UIViewController, set the values you want, and then swap to it using self.tabBarController.selectedIndex.
So for your scenario above it, assuming the UITableViewContollrer is the third view in the UITabBarController, you would do something like the following:
Pass whatever you want into the UITabBarController by setting some pre-defined var in it. For example, if there was a String called saveMe in the UITableViewController, then do the following in the UIViewController:
let navController = self.tabBarController?.viewControllers![2] as! UINavigationController
let tableViewController = navController.viewControllers.first as! JarListTableViewController
tableViewController.saveMe = "Saved string here"
Swap to the UITableViewController using:
self.tabBarController?.selectedIndex = 2
The only issue with this is using selectedIndex won't perform a transition animation but not sure if you need this. This link could help if you do.
I'm trying to use a navigation controller for an identification process in my swift code but each time I click on a button that leads to it, it shows the following black screen:
Here is my storyboard if this can helps, there is no warning and no error in the code (using a drag and drop segue or a programmatically one leads to the same black screen)
Probably the segue you picked: mode & transition.
Are you certain you only have a single segue? It is possible to have overlapping segues, which do not show up clearly in Interface Builder.
Edit
Is there a way we can see all our segues?
Open the Storyboard in its new window
Show Document Outline (leftmost pane)
Show Attribute Inspector (rightmost pane)
Select each View Controller Scene in the Document Outline. The Segues are listed at the bottom. You can inspect Identifier and Segue in the Attribute Inspector.
Sounds, I was doing the wrong way (drag a nav controller, delete the table view, add a new View controller and make the segue), but now if I create a view, and then I embed it in a navigation controller it sounds it works ! Anyway, thanks a lot for your help, this definitely helps me !
I got this when I assigned a custom view to self.view in viewDidLoad:.
self.view = self.mapView
Adding mapView as a subview of self.view solved this.
[I see you've created a custom ViewController, are you sure it's a subclass of ViewController?
You can see which subclass is it off after the ":" in the class declaration!
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.
I have below issue with UIPopoverController and UINavigationController:
I have created one UINavigationController with one UITableViewController in that. Then I have set this UINavigationController to UIPopoverController.I have requirement to have square UIPopoverController so I used setPopoverContentSize of UIPopoverController. I also used contentSizeForViewInPopover.
Issue is when I launch popover it is shown rectangle. But now when I push another UITableViewController by clicking on first UITableViewController row then whole popover is displayed with default size what normally we get.
Please let me know how to overcome this issue.
If more detail is required then let me know.
You have to set the contentSizeForViewInPopover for each view controller you want to push. So for your second UITableViewController as well. Hope this helps.