IOS View controller communicate - ios

Hi I have a view controller A that deal with view A, and a view controller B for view B. Now to go to view B when user click a button in view A?

You can create a UINavigationController , the NavigationController's rootViewController is view A . When the user clicks the button at view A, push View controller B onto the NavigationController. use this method: pushViewController:
good luck with you!

Push View Controller A onto a UINavigationController to begin with. When the user clicks on the button in view A, push View Controller B onto the navigation controller.

Create an IBAction method for the button, initialize your view B, and push it onto the view stack.
This is very well documented in the documentation. You should check it out!

If you are using Storyboard this becomes much much easier. Just select the scene for View A in the Storyboard view, then on the Menu bar, Click Editor->Embed In->Navigation Controller. This will add the Nav Controller automagically and make View A the Root View Controller. Then it is just a matter of wiring up a Segue from View A to View B.

Related

Navigation bar is empty, created from storyboard

This is my story board:
Whenever I jump to a view controller embedded in navigation controller, the navigation bar is shown but empty, why?
The sequence I created it is:
connect buttons with destination view controllers
embed destination view controllers in navigation view controller
And the segue I use is present modally - cross dissolve.
The First root controllers of a navigation controller won't have any Back button attached to its navigation bar. You should add an additional View Controller next to any root View Controller of Navigation Controller with Push Segue ( or Show Segue for newer IOS ) to navigate between them.
I tested different segue transition methods with test projects, the answer I got is: if you are transitioning by presenting it modally, you don't get the back button, you only get it by push.

How to navigate a child view controller from other child view controller in objective c

I want to navigate to a view controller from another controller. Both view controllers are child of root view controller of navigation view controller. Now I want to navigate to a second view controller from the first view controller and same as first view controller from second view controller using navigation view controller. How to do that?
The Storyboard image is as follows :
you can just drag a segue from child1's button to child2, and child2's button to child1, though the storyboard will look ugly, but it works. or you can just use
[self.navigationController pushViewController:child2 animated:YES];
You can setup NavigationController with rootViewController is Controller1
when navigation to Controller2 (from Viewcontroller1) just push viewController2 to navigation controller.
when navigation to Controller1 (from Viewcontroller2) just pop viewController2 from navigation controller (or pop to viewController1).
Make another segue from first View Controller to Second View Controller & give it Push navigation.Also give identifier to segue like 'ABCSegue'. Then On the action of Button write
[self performSegueWithIdentifier:#"ABCSegue" sender:nil];
Do same for navigate from second view controller to first view controller.
Hope this will help you.

Navigating across multiple view controllers

I'm fairly new to iOS development. I'm working on an App that segues to multiple table view controllers. When my application launches, it loads view controller A. I then click on a row in View Controller A to segue to view controller B. The navigation button (back button) in View Controller B shows the title of View Controller A. I then click on a row in View Controller B which will segue to View Controller C. When I click a row in View Controller C, I segue back to View Controller B. My problem is that when I segue from View Controller C to View Controller B, the navigation button (back button) on View Controller B shows the title of View Controller C. I would like it to still show the title of View Controller A. Can anyone help on how this can be done? Sample code will be great. Thanks.
If you are going to use a segue to go from C to B, then you need to use an unwind segue. This has the advantage over using popViewControllerAnimated: in that you can use prepareForSegue to send information back to view controller B just like you would for a forward segue.
You can try to use the popViewControllerAnimated function. Have a look here : http://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/occ/instm/UINavigationController/popViewControllerAnimated:
I think its pretty simple to use so I hope you will not need sample code.

What is the difference between Modal and Push segue in Storyboards?

Can someone explain to me what is the exact difference between modal and push segue?
I know that when we use push the segue gets added to a stack, so when we keep using push it keeps occupying memory?
Can someone please show me how these two are implemented?
Modal segues can be created by simply ctrl-click and dragging to destination but when I do that with the push my app crashes.
I am pushing from a button to a UINavigationController that has a UIViewController.
A push Segue is adding another VC to the navigation stack. This assumes that VC that originates the push is part of the same navigation controller that the VC that is being added to the stack belongs to. Memory management is not an issue with navigation controllers and a deep stack. As long as you are taking care of objects you might be passing from one VC to another, the runtime will take care of the navigation stack. See the image for a visual indication:
A modal Segue is just one VC presenting another VC modally. The VCs don't have to be part of a navigation controller and the VC being presented modally is generally considered to be a "child" of the presenting (parent) VC. The modally presented VC is usually sans any navigation bars or tab bars. The presenting VC is also responsible for dismissing the modal VC it created and presented.
Swift 3.0 and XCode 8.2.1 update
1. Push Segue
Push segue has been renamed as Show segue. To create push segue, the parent view controller needs to be embedded in navigation controller. The navigation controller provides navigation bar. Once you connect two view controller with push segue, the child view controller will automatically has navigation bar on top. The child view controller will be added on top of the navigation stack.
Push segue also provides default features. The child view controller will have a back button that gets you back to the parent view controller. You can also swipe right to pop the child view controller. The animation for push segue is like sliding pages horizontally.
While you are allowed to make a push segue from a view controller that is not in a navigation controller, you will lose all the features like navigation bar, animation, gesture etc when you do so. In this case, you should embed your parent view controller inside navigation view controller first and then make push segue to child view controllers.
2. Modal Segue
A modal segue (i.e. present modally), on the other hand, is presenting over the current view controller. The child view controller will not inherit navigation view controller so the navigation bar will be lost if you present modal segue from a view controller with navigation view controller. You have to embed the child view controller in navigation controller again and start a brand new navigation stack if you want it back. If you want to get back to parent view controller, you have to implement this by yourself and call dismiss from code.
Animation for modal segue is that the child view controller will comes up from the bottom of the page. The navigation view controller is also gone in this demo
The push view must be built in a navigationController.
Click on your master view, then in the menu bar choose:
EDITOR->embed in->navigationController
This is pushing controls using custom push and segue methods for storyboard
And Modal is way to navigate through views without using Storyboards.

UINavigationController shows black screen after pushing a view

I have a storyboard application with a navigation controller an two views controllers ('A', 'B').
In the Storyboard file:
Navigationcontroller is the initial view controller. view controller 'A' is connected to the Navigationcontroller as rootcontroller. View controller 'B' is in storyboard but not connected to any view controller.
when i programmatically try to push view controller 'B' onto the navigationcontroller from inside view controller 'A' with:
B *controllerB = [[B alloc] init];
[self.navigationController pushViewController:controllerB animated:YES];
all i get is a transition to a black screen.
i checked the navigationController property in view controller A at runtime and it´s not nil.
I do not instantiate the navigationController by myself, I let storyboard do the work (maybe that´s the problem). But I think it should be possible to "manually" push view controller to a navigation controller created by storyboard.
When I connect a segue from a button to 'B' in storyboard everything works fine.
Only programmatically it does not work, only shows a black screen inside the navigationcontroller.
Maybe someone could help me with this issue.
I haven't used storyboards yet so this answer is from a glance at the docs. It looks like you can't alloc/init a view controller from a storyboard. You need to use the instantiateViewControllerWithIdentifier: method of your UIStoryboard instance and then you can push the controller.
The accepted answer didn't work for me. I was already using instantiateViewControllerWithIdentifier to navigate to view controller in different storyboard. I am using xcode7.2 and Swift.
I am navigating from storyboard1, some view controller's button action.
Destination is to initial Navigation controller of Storyboard2.
Still I get black screen.
The problem was storyboard2's Navigation controller linked to 1st view controller was linked via show.
Solution:
Delete the link between Nav controller and 1st view controller. Now link it using root view controller. (Ctrl+Click on Navigation controller and drag it to the View controller and Select the option "root view controller")

Resources