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
Related
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.
I have a sidebar menu, made with SWRevealViewController.
I want to switch from the view controller and the view with the button to the next view controller. How I do that?
I try to used the ACTION SEGUE: "push", "modal", "revealview controller" and "revealview controller push controller".
But it doesn't works.
And I try it programmatically switch to the next viewcontroller.
MY CODE:
ViewController2 *vc2 = [[ViewController2 alloc] init];
[self.navigationcontroller pushViewController:vc2 animated:YES]
This change the ViewController, but without the view (blackscreen).
It seems ViewController2 is a ViewController in storyboard. Try the below code:
ViewController2 * vc2 = [[self storyboard] instantiateViewControllerWithIdentifier:#"ViewControllerId"];
You should give Storyboard ID for ViewController2 as ViewControllerId in your storyboard.
Please note that your current ViewController should be in a Navigationcontroller stack to call self.navigationcontroller.
How do I programmatically change from my 1st view controller to my 2nd view controller, which in storyboard is linked to the 1st in storyboard?
My iPad storyboard has a Tab Bar Controller as the "initial View Controller",
which links through a "Relationship Seque view controllers"
to a Navigation Controller, which links through a "root view" link, to View Controller A, which has a UIButton, which links through a 'Manual Seque push' to View Controller B.
Tab Bar Cntrl => Navigation Cntrlr ==(root view)==> View Cntrl A, UIButton ==(push)==> View Cntrl B
So, when running, with View Controller A shown, pressing its UIButton causes the view to change to View Controller B.
There's another UIButton on a UITableView cell on View Controller A. When I press and hold this button, the delegate for UILongPressGestureRecognizer fires ok, and I need View Controller B to now be the view.
How then do I change from View Controller A to View Controller B?
And with VC B open, how do I change back to VC A ?
THE DELEGATE THAT RESPONDS TO PRESS-AND-HOLD............
- (void)schedule_long_press_delegate:(UILongPressGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateEnded) {
printf("Long press Ended ................. \n");
// Get storyboard:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad"
bundle: nil];
printf("mainStoryboard = %x \n", (int)mainStoryboard ); // !!! ax
// Get nav controller for MANAGE view:
UINavigationController *MANAGE_UINavigationController = (UINavigationController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"MANAGE_Storyboard_ID"];
printf("MANAGE_UINavigationController = %x \n", (int)MANAGE_UINavigationController ); // !!! ax
// Get MANAGE view's view controller:
SCHEDULE_UIViewController *schedule_UIViewController = [self.storyboard instantiateViewControllerWithIdentifier:
NSStringFromClass([SCHEDULE_UIViewController class])];
printf("schedule_UIViewController = %x \n", (int)schedule_UIViewController ); // !!! ax
// Change screen to MANAGE view:
[MANAGE_UINavigationController pushViewController: schedule_UIViewController animated:YES];
}
else {
printf("Long press detected ..................... \n");
}
}
STORYBOARD SETTINGS:
UITabBarController ... Storyboard ID is blank.
..links to:
UINavigationController ... Class=UINavigationController StoryboardID = "MANAGE_Storyboard_ID"
..links to:
UIViewController ... Class=acc StoryboardID is blank (INITIAL VIEW)
..links to:
UIViewController ... Class & StoryboardID = "SCHEDULE_UIViewController" (TARGET VIEW)
OUTPUT:..........
mainStoryboard = 1f8b4900
MANAGE_UINavigationController = 1e5d45f0
schedule_UIViewController 2 = 1e5d4b20
In the delegate method for the long press gesture recognizer you can push view controller B from code like this:
ViewControllerB *viewControllerB = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([ViewControllerB class])];
[self.navigationController pushViewController:viewControllerB animated:YES];
You can use a different identifier if you want; using the class name is just my preference.
Changing back to view controller A will be handled for you by the navigation controller. The user will be presented with a back button in the upper left corner.
I have 2 storyboards. I have a situation where I have to navigate from a view controller1 in storyboard 1 to a view controller2 in storyboard 2. The view controller 1 is added as a subview to a parent view controller. When I click on a row in a table view in view controller 1, I have to navigate to storyboard 2.
Initially it was not detecting a touch in the table row. I managed handling it by using a single tap gesture. Now when I click on a row, I am able to navigate to storyboard2 viewcontroller 2 modally. But after navigating ,I am not able to move anywhere on a button click in view controller 2 because it uses all push segues there.
Here is the sample code which I used to navigate.
*NSString * storyboardName = #"OppotunityStoryboard";
NSString * viewControllerID = #"AgreementMainViewController";
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
AgreementMainViewController *controller = (AgreementMainViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
controller.productTransactionentity = productTransactionEntity;
[self presentViewController:controller animated:YES completion:nil];*
You have to embed ViewController 2 in a navigation controller in order for it to be able to use push segues when presented modally.
In my application 2 tabs are there. I am adding tabbarController to the window with two view controllers viewcontroller1 and viewcontroller2 in didFinishLaunchingWithOptions. Now I need to add a button in the viewcontroller1 and in the button action i need to push a new viewcontroller nextViewController. To do this in the button action, i had created a navigation controller and sets its rootview controller as viewcontroller1 and then i push the nextViewController through that navigation controller. But the nextViewController is not getting loaded. Why?
(void) buttonAction {
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:self];
nextViewController *nextViewControllerObj = [[nextViewController alloc]init];
[self.navigationController pushViewController:nextViewControllerObj animated:YES];
}
Instead of adding first tab view controller into UINavigationController, please try adding main UITabBarController into UINavigationController in "didFinishLaunchingWithOptions".