I have already implemented JASidePanelController with storyboards way in a project and it works fine.
I have a Storyboard like this:
[NavigationController] -> [MySidePanelControllerViewController] [LoginVC] -> [HomeVC] -> [ListVC] -> [DescriptionVC]
And the swipe menu is in LoginVC that has Storyboard's ID centrerViewController.
Now I would like to have the swipe menu only in ListVC. How can I do that?
If I give Stroryboard ID centrerViewController to ListVC the application starts at ListVC, not at loginVC.
I have done the same thing but using MFSideMenuContainerViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:_rootNavController
leftMenuViewController:settingDrawerController
rightMenuViewController:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
[self.window setRootViewController:container];
}
and I have set my controller at application delegate and present the loginViewContrller as model view from
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self showLoginView];
}
- (void)showLoginView
{
UIViewController *topViewController = [self.navController topViewController];
if (![topViewController isKindOfClass:[LGLoginViewController class]]) {
[self.navController popToRootViewControllerAnimated:YES];
self.navController = nil;
LGLoginViewController* loginView = [[LGLoginViewController alloc] initWithNibName:#"LGLoginViewController"bundle:nil];
if (!self.navController) {
self.navController = [[UINavigationController alloc] initWithRootViewController:loginView];
} else {
[self.navController initWithRootViewController:loginView];
}
self.navController.delegate = self;
[self.window.rootViewController presentModalViewController:self.navController animated:NO];
}
}
Related
My MainViewController loads another view modally.
#implementation MainViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *uiViewController = [storyboard instantiateViewControllerWithIdentifier:#"splashViewController"];
[uiViewController setModalPresentationStyle:UIModalPresentationCustom];
[uiViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:uiViewController animated:YES completion:nil];
}
When I load the MainViewController directly from the AppDelegate, the modal view is loaded.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIViewController *rootController = [[RootViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
[navigationController setNavigationBarHidden:true];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
return YES;
}
If I load the MainViewController as a child controller of another controller, then the modal view fails to load.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.drawerViewController.leftViewController = self.leftDrawerViewController;
self.drawerViewController.centerViewController = self.mainViewController;
self.drawerViewController.animator = self.drawerAnimator;
UIViewController *rootController = self.drawerViewController;
navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
[navigationController setNavigationBarHidden:true];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
return YES;
}
The main view still loads. It's only that the modal view is not created.
What's causing the problem and how can I resolve this?
You should not present another view controller from viewDidLoad method ,
by that time , current view is NOT finished with its view-hieararchy changes ,
You can present new viewcontroller after viewDidAppear is called ,
so you can move that code to viewDidAppear
I have a project that works well in other simulators including The New iPad. However, with the iPhone5, it crashes when calling the Viewcontroller in delegate
I don't know why this error happens. Please let me know if you discover any possible causes in the code below:
self.rootviewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
self.rootNavController = [[UINavigationController alloc]
self.rootNavController.navigationBar.hidden=YES;
[window addSubview:rootNavController.view];'
Please see image below:
Thank you very much
I think you do something wrong with the creation of your UINavigationController, try the following code to replace yours in your AppDelegate.m :
EDIT add code to display and remove splashscreen with UIViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Create View Controller
RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
// Create Navigation Controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
// Create Navigation Controller
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
// SplashScreen
[self displaySplashscreen];
return YES;
}
#pragma mark - SplashScreen Methods
- (void)displaySplashscreen
{
// Create View
self.splashscreenViewController = [[SplashscreenViewController alloc] init];
// Display Splashscreen
[_window addSubview:_splashscreenViewController.view];
// Dismiss Splashscreen
[self performSelector:#selector(dismissSplashscreen) withObject:nil afterDelay:3.0f]; // Modify the time
}
- (void)dismissSplashscreen
{
// Splashscreen Animation
[UIView animateWithDuration:0.5f
animations:^{
_splashscreenViewController.view.alpha = 0.0f;
} completion:^(BOOL finished) {
[_splashscreenViewController.view removeFromSuperview];
}];
}
I want to make a simple navigation control application in which I have two view controllers(ViewController and ViewController2). I have a button in ViewController and when I press the button, I want it to go to the other view. The problem is that button doesn't work. I also tried the UIViewController, but didn't work in that way neither.
The AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
ViewController *vc1 = [[ViewController alloc]init];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc1];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
[self.window addSubview:nav.view];
return YES;
}
The ViewController.m
- (IBAction)myButton:(id)sender {
ViewController *vc2 = [[ViewController alloc]init];
[[self navigationController]pushViewController:vc2 animated:YES];
}
Thanks in advance for your help
if you use storyboard import in your ViewController1 the ViewController2 and give a storyboard ID to it "view2":
ViewController2 *vc2 = (ViewController2 *)[self.storyboard instatiateViewControllerWithIdentifier:#"view2"];
[self.navigationController pushViewController:vc2 animated:YES];
I'm trying to determine which tab has been selected by the user. I melded this together from a couple of tutorials on iOS tab bars. In my appDelegate I have this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//We need to implement the view controllers within the tab controller and make the tab controller the root controller of our app - note we are only using view 1-3 at first.
FirstViewController *fistView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
ThirdViewController *thirdView = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
FourthViewController *fourthView = [[FourthViewController alloc] initWithNibName:#"FourthViewController" bundle:nil];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:fistView, secondView, thirdView, fourthView, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
self.window.rootViewController = self.tabController;
//end custom code
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Is viewControllerArray the delegate for my tabController?
When I place this code on the page nothing happens:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (tabBarController.selectedIndex == 0) {
NSLog(#"ok");
}
}
In this case, your app delegate should be the delegate for the tabBarController.
You can simply add self.tabController.delegate = self and make sure that your AppDelegate conforms to the UITabBarControllerDelegate protocol.
I also suggest placing a log outside the if in your delegate method, to confirm that it is actually called.
I want to use this ECSlidingViewController in my project. Example app from link uses storyboards, but i want to load all from xibs.
What i must implement in application:didFinishLaunchingWithOptions: to do this?
Code from example app:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)self.window.rootViewController;
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
storyboard = [UIStoryboard storyboardWithName:#"iPhone" bundle:nil];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:#"iPad" bundle:nil];
}
slidingViewController.topViewController = [storyboard instantiateViewControllerWithIdentifier:#"FirstTop"];
return YES;
}
Instead of using storyboards to get an instance of the UIViewController, you can instantiate it from a nib:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
ECSlidingViewController *slidingViewController = [[ECSlidingViewController alloc] init];
FirstTopViewController *firstTop = [[FirstTopViewController alloc] initWithNibName:#"FirstTop" bundle:nil];
slidingViewController.topViewController = firstTop;
self.window.rootViewController = slidingViewController
return YES;
}
Try this that worked on my env.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.initialViewController = [[InitialViewController alloc] initWithNibName:#"InitialViewController" bundle:nil];
self.window.rootViewController = self.initialViewController;
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)self.window.rootViewController;
FirstViewController *firstController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
slidingViewController.topViewController = firstController;
[self.window makeKeyAndVisible];
return YES;
}
and also do not forget to add
[self.slidingViewController setAnchorRightRevealAmount:280.0f];
into your firstviewcontroller's viewWillAppear method.
Good luck