How can i go to storyboard from xib - objective-c

i am using both storyboard and xib in my project and i want to go xib files from storyboard but can't reverse it. so how i go to storyboard from xib files. thnx in advance.
storyboard to xib:
Dashboard1ViewController *tempView = [[Dashboard1ViewController alloc] initWithNibName:#"Dashboard1ViewController" bundle:nil];
tempView.passemail = [matches valueForKey:#"email"];
[self.view addSubview:tempView.view];
it works fine but xib to storyboard i have used this code
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"loginUI" bundle:nil];
login2ViewController *vc = [sb instantiateViewControllerWithIdentifier:#"login2"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
but it is not working.

Change nil to [NSBundle mainBundle]
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"loginUI"
bundle:[NSBundle mainBundle]];

the following method is working for me. make sure that your identifier is correct
YourViewController *urViewController = (YourViewController *)[[UIStoryboard storyboardWithName:storyboardName bundle:nil] instantiateViewControllerWithIdentifier:#"storyboardID"];
[self presentViewController:urViewController animated:YES completion:nil];

Related

Loginviewcontroller before SWRevealviewcontroller with Storyboard objective C

I am using SWRevealViewcontroller by using this sample:
I want to add loginviewcontroller before SWRevealViewcontroller.
What I've tried:
Added loginviewcontroller in Storyboard. Set it as InitialViewcontroller.
Inside button action.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MapViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"MapViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[navController setViewControllers: #[rootViewController] animated: YES];
[self.revealViewController setFrontViewController:navController];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
But it is not working. Please help
viewController1
viewController2 *viewController2=[self.storyboard instantiateViewControllerWithIdentifier:#"viewController2Id"];
[self.navigationController pushViewController: viewController2 animated:YES];
viewController2
-(void)pushAfterLoginScreen
{
SidebarViewController *sidebarmemu =(SidebarViewController*) [self.storyboard instantiateViewControllerWithIdentifier:#"SidebarController"];
viewController3* viewController3 = (viewController2*)[self.storyboard instantiateViewControllerWithIdentifier:#"viewController2Id"];
SWRevealViewController *revealController;
UINavigationController *frontNavigationController;
UINavigationController *rearNavigationController;
frontNavigationController =[[UINavigationController alloc]initWithRootViewController: viewController2];
rearNavigationController =[[UINavigationController alloc]initWithRootViewController:sidebarmemu];
revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
self.swcontroller =revealController;
AppDelegate *app =(AppDelegate *)[[UIApplication sharedApplication]delegate];
app.window.rootViewController =self.swcontroller;
}
SWRevealViewcontroller which is already embed with the navigationController you need to pass control to SWRevealViewcontroller after successful login using presentViewController method by setting up the storyboard id to navigationController of SWRevealViewcontroller and navigate your app using below code:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"navContStoryboardID"];
[vc setModalPresentationStyle:UIModalPresentationCustom]; // optional
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; // optional
[self presentViewController:vc animated:YES completion:nil];
Hope this helps you.

Presenting a view controller in tvOS

I am trying to present a view controller in a tvOS application, but neither of the included code snippets present one. What am I missing?
Code 1 :
DinoViewController *dinoVC = [[DinoViewController alloc]init];
dinoVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:dinoVC animated:YES completion:nil];
Code 2 :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
DinoViewController *dinoVC = [storyboard instantiateInitialViewController];
dinoVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:dinoVC animated:YES completion:nil];
Found the correct answer: Mention Identifier in the tvOS storyboard, (not the same in iOS,) and then implement this code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *dinoVC = [storyboard instantiateViewControllerWithIdentifier:#"Page1"];
[self presentViewController:dinoVC animated:YES completion:nil];
Please try this..
DinoViewController *dinoVC = [[DinoViewController alloc]init];
dinoVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self showViewController:dinoVC sender:nil];
hope this will hope u

Present modal UIViewController over UISplitViewController from AppDelegate

I've written the code below to present a modal UIViewController on top of a UISplitViewController from AppDelegate. However, it keeps throwing Application tried to present modally an active controller <UISplitViewController: 0x138023800>..
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
NSLog(#"%#", shortcutItem.type);
if([shortcutItem.type isEqualToString:#"com.myapp.show-me"]){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UISplitViewController *tc = [storyboard instantiateViewControllerWithIdentifier:#"SplitViewController"];
self.window.rootViewController = tc;
UINavigationController *ivc = [storyboard instantiateViewControllerWithIdentifier:#"Navigation"];
UIViewController *detailViewController = [ivc.viewControllers objectAtIndex:0];
detailViewController.restaurant = #"1";
[tc presentViewController:detailViewController animated:YES completion:nil];
} else if([shortcutItem.type isEqualToString:#"com.myapp.see-all"]){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UISplitViewController *tc = [storyboard instantiateViewControllerWithIdentifier:#"SplitViewController"];
self.window.rootViewController = tc;
}
}
What am I doing wrong with com.myapp.show-me?
As it turns out, I only needed to present the UINavigationController instead of the UIViewController.
[tc presentViewController:ivc animated:YES completion:nil];

Could not load NIB in bundle with name 'SecondViewController'

I'm trying to push the Navigator Controller to a different view controller but I keep getting the error saying the nib bundle name can't be loaded. Here's the code I'm using:
SecondViewController *vc1 = [[SecondViewController alloc]
initWithNibName:NSStringFromClass([SecondViewController class]) bundle:Nil];
[self.navigationController pushViewController:vc1 animated:YES];
You have to pass the name of the nib file, not the class name:
// Assuming there is a properly set up SecondViewController.xib in your project.
SecondViewController *vc1 = [[SecondViewController alloc]
initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:vc1 animated:YES];
EDIT:
If you're using Storyboards, you have to load your GUI a bit differently:
UIStoryboard *sboard = [UIStoryboard storyboardWithName:#"StoryboardFileName"
bundle:nil];
SecondViewController *vc1 = [sboard instantiateInitialViewController];

How to load a login view controller from app delegate

Here's the situation. I have an NSTimer in Appdelegate.m that performs a method that checks the users location and logs him out if he is out of a region. When that happens I want to load the login view controller. However, with the following lines of code, I am able to see the VC but if I click on a textfield to type, I get a sigbart. Any ideas how to load the initial VC from app delegate correctly?
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
LoginViewController *loginViewController = (LoginViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:#"Login"];
[self.window addSubview:loginViewController.view];
[self.window makeKeyAndVisible];
I've been struggling with this quite a bit. Here's what worked for me
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
LoginViewController *loginViewController = (LoginViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:#"Login"];
//set the root controller to it
self.window.rootViewController = loginViewController
If you're still having errors, it has to do with your LoginViewController, not the AppDelegate transition. Hope this helps.
Both audiophilic and Flaviu 's approaches are ok. But both of you are missing one extra line of code.
I found out that you have to allocate and init the UIWindow object first. I dont know why but initializing the object solved the problems.
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
audiophilic's approach:
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
ResultsInListViewController *resultsInListViewController = (ResultsInListViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:#"ResultsInListViewController"];
[self.window addSubview:resultsInListViewController.view];
[self.window makeKeyAndVisible];
Flaviu's approach:
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
ResultsInListViewController *resultsInListViewController = (ResultsInListViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:#"ResultsInListViewController"];
[self.window setRootViewController:resultsInListViewController];
[self.window makeKeyAndVisible];
This is the code I use when I want to change views:
#import "LoginViewController.h"
LoginViewController *screen = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
//or
[self.window addSubView:screen];
Using that code will create a brand new instance of it and show it, so it should accomplish your question. You may have to move some things around, but it should work.
Let me know if you need any more help.
Hope this helps you!