iOS - Setting first Screen after LaunchScreen - ios

Im new to iOS development coming from an Android background and im looking to set the first screen after the launch screen.
I believe the relevant code is
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [UITabBarController new];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];
The XIB file for the screen i want to set to first screen is called LoginView.xib
What do i need to do?
The boilerplate app im using is a mix of Swift and Objective C
Thanks

You also need to set the view controllers that should be handled by the tabbar controller. In your case, you need to instantiate the view controller that displays the view in LoginView.xib - I assume it is called LoginViewController:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [UITabBarController new];
LoginViewController *lvc = [[LoginViewController alloc] init];
// SecondViewController *secondVC = [[SecondViewController alloc] init];
// ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
rootViewController.viewControllers = #[lvc /*, secondVC, thirdVC */ ];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];
If you don't want a tab bar controller initally, then just use
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [LoginViewController new];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];

Related

LeftSideMenu in MFSideMenu not responding

I'm implementing MFSideMenu in my project and this is my AppDelegate Code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[[UINavigationController alloc]
initWithRootViewController:[[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil]]
leftMenuViewController:[[SideViewController alloc] initWithNibName:#"SideViewController" bundle:nil]
rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;
}
The menu appear correctly and all of it's contents but the components inside it (button, tableview, etc...) not responding to any interaction . I've created a new clean project and add the menu only on it but with no hope.
Thanks in advance
you can try like this
SideViewController *leftMenuVC = [[SideViewController alloc] initWithNibName:#"SideViewController" bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[[UINavigationController alloc]
initWithRootViewController:[[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil]]
leftMenuViewController:[[UINavigationController alloc]initWithRootViewController:leftMenuVC] rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;

Switching root view controller

I've an app with UINavigationController already, but i want to switch to UITabBarController, the problem is when i switch to UItab from beginning it doesn't work, so i'm switching it in a delegate method but it doesn't work either!
all code in the app delegate.
self.navigationController = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]];
self.tabBarController = [[UITabBarController alloc] init];
if ([PFUser currentUser]) {
// Present wall straight-away
[self presentWallViewControllerAnimated:NO];
} else {
// Go to the welcome screen and have them log in or create an account.
[self presentLoginViewController];
}
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
The delegate method i want to switch on it:
- (void)presentWallViewControllerAnimated:(BOOL)animated {
NSLog(#"Called:presentWallViewControllerAnimated ");
// self.navigationController = nil;
self.tabBarController = [[UITabBarController alloc] init];
PAWWallViewController *wallViewController = [[PAWWallViewController alloc] initWithNibName:nil bundle:nil];
wallViewController.delegate = self;
// Set up the first View Controller
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.view.backgroundColor = [UIColor orangeColor];
vc1.tabBarItem.title = #"Orange";
vc1.tabBarItem.image = [UIImage imageNamed:#"heart"];
// Set up the second View Controller
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.view.backgroundColor = [UIColor purpleColor];
vc2.tabBarItem.title = #"Purple";
vc2.tabBarItem.image = [UIImage imageNamed:#"star"];
// Set up the Tab Bar Controller to have two tabs
[self.tabBarController setViewControllers:#[ vc1, vc2]];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
// [self.window addSubview:tabBarController.view];
// [self.navigationController setViewControllers:#[ tabBarController ] animated:animated];
}
Remember to handle the view transition:
UIViewController *vc = // any vc that's initialized properly
window.rootViewController = vc;
[UIView transitionWithView:window
duration:0.3 // 0.0 for immediate
options:UIViewAnimationOptionTransitionCrossDissolve // several enums to choose from here
animations:nil
completion:nil];
and you don't need makeKeyAndVisible after the first time.
You called - (void)presentWallViewControllerAnimated:(BOOL)animated but in the end of didFinishLaunchingWithOptions you called
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
So the tab bar will never works !

App Delegate call for Apple Push Notification doesn't present viewcontroller

I have embedded apple push notifications to my app. When a notification is popped, I get an alert view and when clicked on view, I navigate to a Details controller. But, after clicking on the view button, it does not do anything and it freezes the application. Here's my code to open details in alert view click:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
RearTableViewController *rearView = [[RearTableViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
[self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
[self.window makeKeyAndVisible];
Thanks in advance!
//Don't realloc self.window.
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
//Alloc this VC with nib name like initWithNibNamed:bundle:
RearTableViewController *rearView = [[RearTableViewController alloc]initWithNibName:#"RearTableViewController" bundle:nil];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
if(self.window.rootViewController){
[self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
}
else{
self.window.rootViewController = mainRevealController;
}
[self.window makeKeyAndVisible];
Hope it will work.
Remove the following code.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
No need to allocate the window once again. If you do so, you have to set the rootViewController again.

MFSideMenu - center view doesn't resize

I'm using MFSideMenu following the setup instructions, putting in didFinishLaunchingWithOptions this code:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SideMenuViewController *leftMenuViewController = [[SideMenuViewController alloc] init];
SideMenuViewController *rightMenuViewController = [[SideMenuViewController alloc] init];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[self demoController]
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;
I have tested this in demo project MFSideMenuDemoBasic, replacing [self navigationController] with [self demoViewController] simply because I don't want to use a navigation controller.
The problem is that the center view controller doesn't resize properly, it remains the same size also if running on iPad.
I'm having the same behaviour in my project and probably I'm missing something obvious.
add this to your demoController's viewDidLoad method (it worked for me):
self.view.frame = [[UIScreen mainScreen] bounds];
verify your view has autosizing set correctly...

UITableViewController in UITabBar

I'm trying to create a UITabBarController around my UITableView Controller. I'm using this code. But the problem is that when this is used the Navigation Bar disappears. How do I work around this?
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
StyledTableViewController *viewController1 = [[StyledTableViewController alloc] initWithNibName:#"StyledTableViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
Need to add UINavigationController to Navigation Bar plus it matain your hierarchy of views
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
StyledTableViewController *viewController1 = [[StyledTableViewController alloc] initWithNibName:#"StyledTableViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:viewController1];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[navController];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;

Resources