Sidebars on different ViewControllers using same SWRevealViewController - ios

I have used SWRevealViewController to create side bar. As in this I have used my HomeViewController as front and SidebarViewController as right.
My SidebarViewController contain a UITableView(Having different subject names). I want to open a new ViewController say QuestionsViewController on selection of any subject.
Now my problem is I want to use SWRevealViewController again to have a sidebar in QuestionViewController but in SWRevealViewController identifier for front segue sw_front is a constant string so how can I change it or having any other way to have that sidebar in QuestionViewController also.
In Short : Can we have same sidebars in different ViewControllers using SWRevelViewController

Try this one:
create NavigationViewController with HomeViewController,
segue the RevealViewController to the NavigationController as "reveal view controller set controller",
segue HomeViewController to the QuestionViewController as "show",
on both add "bar button item"(named:"OpenSideBar") on the left of the NavBar,
create an outlet to both in their swift files and add to your viewDidLoad next:
OpenSideBar.target = self.revealViewController()
OpenSideBar.action = Selector("revealToggle:")
**worked for me

Simply connect your RevealViewController to your new view controller with "reveal view controller set controller" segue

I got a solution for this, we can change front and rear ViewControllers by using following code.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
[self.revealViewController setRightViewController:[storyBoard instantiateViewControllerWithIdentifier:#"SideBarVC"]]; // To change rightViewController
[self.revealViewController setFrontViewController:[storyBoard instantiateViewControllerWithIdentifier:#"HomeVC"] animated:YES]; // To change frontViewController
For this we have to use SWRevealViewControllerSeguePushController as segue class for other FrontViewControllers
Thanks everyone for your help.

Related

SWRevealViewController with TabBarController

I use SWRevealViewController in my project. My app have TabBarController. I did that I open the menu. When I select in menu it open without TabBarController bottom. I use Storyboard. My start View is ViewController with class SWRevealViewController. I connect to my menu with identifier sw_rear and class SWRevealViewControllerSegueSetController. Before menu I have Navigation Controller. I also connect SWRevealViewController to my TabBar with identifier sw_front and class SWRevealViewControllerSegueSequeController. What am I doing wrong?
In my menu to open a View I have this code:
BookTableViewController *m = [self.storyboard instantiateViewControllerWithIdentifier:#"Book"];
[self.revealViewController pushFrontViewController:[[UINavigationController alloc] initWithRootViewController:m] animated:YES];
[self.revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];
//Tabbar controller name on storyboard
Tabbarcontroller *tabvc=(Tabbarcontroller *)[self.storyboard instantiateViewControllerWithIdentifier:#"TabbarcontrollerVCId"];
NSLog(#"tabvc controller ===>%#",tabvc.viewControllers);
Select viewcontollers and pass index
tabvc.selectedIndex=0;
[self.revealViewController setFrontViewController:tabvc];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
From what I understand, you want the front viewcontroller to be a tab bar and a menu with no tab bar?
So there are three things, front, rear and right. If you have not already look at the AppDelegate in RevealControllerExample and try do the following,
Create an instance of your tabbar
Create SWRevealViewController, init with nil as the rear and your tabbar as the front (if you can't use nil as the rear, just create a UIViewController, but you won't use it).
Create you menu viewcontroller and assign it to the rightViewController property of the SWRevealViewController
If this does not solve your problem please comment, good luck.

ViewControllers overlapping each other in Main.Storyboard

I've two ViewControllers in Main.Storyboard, entry point ViewController have green background, and another is red background. At the button click of first ViewController it should show second ViewController, but the first and second ViewControllers are overlapping each other and both ViewControllers Buttons are clickable.
Ist view controller (green), bingo is the UIButton
2nd view controller (red), hello is the UIButton
On the click event of the button in first view controller is :
MViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:#"mvc"];
[self presentViewController:mvc animated:YES completion:nil];
Try this if its a push segue :
MViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:#"mvc"];
[self.navigationController pushViewController:mvc animated:YES];
And you should take one navigation controller and assign it as initial view and make green view the root view. Delete the default root view controller comes with it.
You can write this code in the action block of bingo button
{
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let redVC = storyBoard.instantiateViewControllerWithIdentifier("**RedViewControllerSID**") as RedViewController
self.presentViewController(redVC, animated:true, completion:nil)
}
go storyboard and create Storyboard ID as RedViewControllerSID

Switch from View Controller to Tab Bar Controller in a Storyboard xCode

I am working on an app in xCode 5. This is a first at using the Storyboard. My app starts with a simple username/password login screen. Upon successful login, I want to programmatically switch from this login View to my Tab Bar Controller with the tab index set at 1.
I do not have a custom class for my UITabBarController. I can build one if need be. Can someone help get me started or point me in the right direction?
Funny how typing out the question can help you solve it. Here is the code I used in case someone has the same issue in the future
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
UITabBarController *vc = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:#"UITabBarController"];
[self presentViewController:vc animated:YES completion:nil];
[vc release];
If you have only one storyBoard in your project then you can also use simply
self.storyboard
The best way to do this is to set your rootviewController to tabBarcontroller as soon as you authenticate the user. Here is how you can do this in swift.
let tabBarController = self.storyboard?.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = tabBarController
Where TabBarController is the storyboard id of your tab bar controller. It could be anything whatever name you have given it.
In storyboard; drag a segue from your ViewControllers button (or File's Owner to connect a method) to your TabBarVC. Choose modal style and animation if you wish.
Add a new custom class for UITabBarController and assign it to TabBarVC in storyboard.
In it's implementation file; put self.selectedIndex = 1;

'Push segues can only be used when the source controller is managed by an instance of UINavigationController

I am having a problem with this.
In my root view controller I am having a textfield & one button. I am giving a condition like if i entered 0 in textfield then only it should move to next view.
upto here it is working correctly. But now here is problem. Here I am having one button & given navigation to third view controller for that button. here i am getting error as
Terminating app due to uncaught exception 'NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
image ref: http://img12.imageshack.us/img12/8533/myp5.png
and i am giving action for button in first view as below
- (IBAction)Submit:(id)sender {
if([tf.text isEqual:#"0"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
SecondViewController *vc2 = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewControllerID" ];
[self presentViewController:vc2 animated:YES completion:NULL];
}
}
Go To:
Editor--> Embed In --> Navigation Controller, to add Navigation Controller to your initial view
After looking at your screenshot, you either need to
Push your SecondViewController onto the existing navigation controller's stack instead of presenting it modally OR
You need to embed your SecondViewController in another navigation controller and then create and present that navigation controller modally from your SamplesViewController
Either way, SecondViewController needs to be embedded in a navigation controller before you can use Push Segues from it
Either embed your view controller in a Navigation controller or if there is a Navigation controller in the story board mak it the initial view controller
I also faced same problem. My problem was I was using model segue style (rather that push) for one before the current controller because of that I think it broke the Navigation chain before already.
Embed your view controller in a UINavigationController is a good option if there is no UINavigationController in the storyboard. Otherwise you can select the UINavigationController and select the root view controller in the inspector pane, then drag it to the UIViewController you want to use as root. the screenshot is as below:
I solved this by creating a custom UIStoryboardSegue between the UINavigationController and the destination view controller:
-(void) perform
{
assert([self.sourceViewController isKindOfClass:[MyNavigationController class]]);
MyNavigationController *launchController = (MyNavigationController *) self.sourceViewController;
[launchController setViewControllers:#[self.destinationViewController] animated:YES];
}
Try this. It works for me.when you set root view controller to first view and use self.presentViewController ,controller move to next view but instance of navigation controller is only for first view,third view required navigation instance so use self.navigationController instead of presentViewController.
NSString * storyboardName=#"Main";
UIStoryboard *storybord=[UIStoryboard storyboardWithName:storyboardName bundle:nil];
SecondViewController *vc=[storybord instantiateViewControllerWithIdentifier:#"SecondViewControllerID"];
[self.navigationController pushViewController:vc animated:YES];

Storyboard UITabBaar, initiate two different views from button

I've created a storyboard that has a UITabbarController all is working well but now I want to add some logic that determines which viewcontroller a particular tabbar button will display.
Example... if a customer has a valid subscription display viewcontroller one, if no subscription display viewcontroller two.
Is this possible using storyboards, I've looked at UITabBarDelegate and prepareForSegue but struggling to piece this together?
Are there any examples of how to do this sort of thing using StoryBoards?
Many thanks
You can set it like this:
if(hasSubscription)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
ViewController1* subsection = [storyboard instantiateViewControllerWithIdentifier:#"ViewController1"];
ViewController2* subsection1 = [storyboard instantiateViewControllerWithIdentifier:#"ViewController2"];
[(UITabBarController*)self.window.rootViewController setViewControllers:[NSArray arrayWithObjects:subsection,subsection1, nil]];
}
If you want to add rootviewController according to the subscription then above answer given by soryngod is good one.
But if you want to open viewControllers after rootviewcontroller loaded, then at tabBarButton press perform following code:-
before this code, add yours viewControllerONE and viewControllerTWO to the rootViewController by segues as shown: . And give each segue an identifier in AttributeInspector, example "one" for viewControllerONE and "two" for viewControllerTWO.
then at tabBarButton action do the following:-
if(subscription)
[self performSegueWithIdentifier:#"one" sender:self];
else
[self performSegueWithIdentifier:#"two" sender:self];

Resources