iOS:Passing data to front SWRevealViewController - ios

I have the following viewControllers:
When I click the "Go to gray" it loads the gray viewController using SWRevealViewController.
Here is my code:
#import "SWRevealViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (IBAction)gotoGray:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
SWRevealViewController *swrController = [storyboard instantiateViewControllerWithIdentifier:#"SWRevealViewController"];
[self presentViewController:swrController animated:YES completion:nil];
}
My Question to you guys is how can pass data from the blue view controller to the gray (front SWRevealViewController) ?
I'll really appreciate your help.

You have a reference to it with SWRevealViewController *swrController, you can set data on the reference by using information from the presenting view controller.
- (IBAction)gotoGray:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
SWRevealViewController *swrController = [storyboard instantiateViewControllerWithIdentifier:#"SWRevealViewController"];
swrController.aProperty = self.myInformation;
swrContoller.anArray = self.arrayOfInfo
[self presentViewController:swrController animated:YES completion:nil];
}

Related

why use storyboard push a viewcontroller shows black screen

I created a SingleView application then use "Embed In Navigation Controller" to get a navigation control.
when push a controller, the viewcontroller's backgroundColor is black.
i know use this code :
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];//UIStoryboard(name: "Main", bundle:nil)
UIViewController *roomController = [storyBoard instantiateViewControllerWithIdentifier:#"controlerID"];
but what's the reason ?
and if i don't want to use the storyboard completely ,only use this code
UIViewController *roomController = [[UIViewController alloc]init];
what can i do? is only set the viewcontroller's backgroundColor?
You need to use the instantiateViewControllerWithIdentifier: method of your UIStoryboard instance and then you can push the controller.
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *roomController = [storyboard instantiateViewControllerWithIdentifier:#"controlerID"];
[self.navigationController pushViewController: roomController animated:YES];
// if You make controller with out storyboard Than change You view color
UIViewController *roomController = [[UIViewController alloc]init];
[self.navigationController pushViewController: roomController animated:YES];
- (void)viewDidLoad
{
self.view.backgroundColor =[UIColor whiteColor];
}

Change View on successful registration using storyboard

I have three UIViewControllers ViewController, HomeViewController and RegisterViewController using storyboard. Their Storyboard ID is Login, Home and Registration respectfully. There is a button on RegisterViewController view named 'Register'. After successful registration i want to go to home page i.e., HomeViewController. How to do it. Please help I'm new to iOS.
thanks
- (IBAction)yourRegisterButtonAction:(id)sender
{
[self performSegueWithIdentifier:#"YOUR_SEUGE_NAME" sender:nil];
}
Try This
- (IBAction)buttonRegister:(id)sender {
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
// replace Main with your storyboard name
HomeViewController *homeVC = [storyboard instantiateViewControllerWithIdentifier:#"Home"];
[self.view addSubview:homeVC.view];
}
Implement a navigation controller and do this.
-(IBAction)registerButtonTapped:(id)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
HomeViewController *viewController =(HomeViewController*) [storyboard instantiateViewControllerWithIdentifier:#"Home"];
[self.navigationController pushViewController:viewController animated:YES];
}

Navigate in uiviewcontroller iOS

I have a problem in memory management, when navigate to specific UIViewController
Example:
I have 3 UIViewController and use Storyboard modal segue and I stay in the first and I need go to the number 3 directly
I use this code works fine, but when i need return to the 1 and I if repeat this code. I receive a memory warning and crash later.
This is my code:
go to view 3 ->
UIStoryboard *storybord = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * viewTree = [storybord instantiateViewControllerWithIdentifier:#"Three"];
[self presentViewController:viewTree animated:YES completion:nil];
go to view 1 ->
UIStoryboard *storybord = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * viewOne = [storybord instantiateViewControllerWithIdentifier:#"One"];
[self presentViewController:viewOne animated:YES completion:nil];
You must be constantly be presenting each view controller over each other, which is raising the memory warning issue. To present ViewControllerThree use the following code in ViewControllerOne
#implementation ViewControllerOne
- (IBAction) goto3 {
UIStoryboard *storybord = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * viewTree = [storybord instantiateViewControllerWithIdentifier:#"Three"];
// Brings you to the third view controller.
[self presentViewController:viewTree animated:YES completion:nil];
}
#end
And then to go back to ViewControllerOne implement this code in ViewControllerThree
#implementation ViewControllerThree
-(IBAction) backTo1 {
// Dismisses the third view and brings you back to the first view controller.
[self dismissViewControllerAnimated:YES completion:nil];
}

How to get the navigation bar on view controller?

I have three View controller A,B,C.I have navigation controller attached to A view controller.In A i have some buttons,I have attached the button segue to B view controller.Onclick of the button i go to the B view controller.On B View controller i have UITableView on click of table view item i am launching the C view controller.below is the code for that
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0)
{
NSLog(#"first cell");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"BusinessCard"];
[self presentViewController:vc animated:YES completion:nil];
}
else if(indexPath.row==1)
{
NSLog(#"second cell");
}
else if(indexPath.row==2)
{
NSLog(#"third cell");
}
}
But on C view controller the navigation Bar is not appearing.I think C view controller is not linked to the Navigation Controller.
You use navigationController push method to display navigation bar in C viewController
try this code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"BusinessCard"];
[self.navigationController pushViewController:vc animated:YES];
Use the code below
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"BusinessCard"];
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:nil];
You need to present it using UINavigationController as modal.
Hope it helps.
use this:
[self.navigationController pushViewController:vc animated:YES];
You can use "Push" segue and embed your ViewController in Navigation Controller, and then use its Navigation Controller's functions like pushViewController and popViewControllerAnimated
Answer are all correct, but i just want to explain things..
//This line gets the storyboard with the name "Main" which contains all
//the setup you made for UI (User interface)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
//While this like gets the view inside your storyboard with
//storyboard ID/indentifier `BusinessCard `
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"BusinessCard"];
//Lastly, this line is correct presenting the viewcontroller BUT this doesn't add your
//viewcontroller to the array of viewControllers inside navigationController
//
//Also, this line makes you present the viewController above the
//rootViewController of window which is in your case the navigationController
//
This is you Error
[self presentViewController:vc animated:YES completion:nil];
//This is what you are looking for, and the correct one for your implementation
//
//This will let you add the `vc`(viewController) to the array of viewController
//in navigationController, to confirm that you can check the `self.navigationController.viewControllers`
//which will return the array of viewController inside your navigationController
This is the Answer
[self.navigationController pushViewController:vc animated:YES];
Hope this helps you, and my explanation is apprehendable.. Cheers

iOS -navigate from AppDelegate to FrontViewController of SWRevealViewController

I try navigate to FrontViewController of SWRevealViewController from AppDelegate
In AppDelegate.m
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
Home_tableView *home =[storyboard instantiateViewControllerWithIdentifier:#"home_view"];
[(UINavigationController *)self.window.rootViewController pushViewController:home animated:NO];
when it load my Home_tableView.m in viewDidLoad method,I got self.revealViewController is nil & its crash
SWRevealViewController *revealViewController = self.revealViewController;
_nav_bar.target = self.revealViewController;
_nav_bar.action = #selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
My storyboard like this
you have to try like this may be help you.
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:#"revealidentifier"];
Now use vc as your revealViewController.
NOTE: You have to enable navigationcontroll "FirstViewController"
I think you are using SWRevealViewController which is on Github
and you can follow this tutorial to integrate it into your app.
this is really amazing tutorial and it will help you
http://www.appcoda.com/ios-programming-sidebar-navigation-menu/
Thank to #Dipen Chudasama I get the answer
in my AppDelegate.m file , I put this code to navigate to my slide menu (SWRevealViewController)
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
SWRevealViewController *home = [storyboard instantiateViewControllerWithIdentifier:#"reveal"];
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:home animated:YES completion:NULL];
Thank you for every one try to help me

Resources