ECSlidingViewController loading from XIB - ios

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

Related

How to instantiate and push an (additional) storyboard into my app?

My app is mainly constructed without storyboards.
However, I have created just one for the registration of users.
This storyboard consists of a navigation controller containing 2 views controllers.
The first one is called "FirstVC", and the one "SecondVC" (this one would not be used for my question).
I am trying to push it in the AppDelegate.m file (trying various ways, see below) but my screen is always black.
attempt 1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"FirstRegistration" bundle:nil];
FirstVC *fvc = [sb instantiateViewControllerWithIdentifier:#"FirstVC"];
UINavigationController *navController =(UINavigationController *)self.window.rootViewController;
[navController pushViewController:fvc animated:YES];
return YES;
}
attempt 2
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"FirstRegistration" bundle:nil];
FirstVC *fvc = [sb instantiateViewControllerWithIdentifier:#"FirstVC"];
self.window.rootViewController = fvc;
return YES;
}
Note : I've set the FirstVC scene to FirstVC in the identifier Custom Class section and also set the storyboard ID to FirstVC. However I have not touched to the NavigationController scene, should I just set the custom class to UINavigationController ?
can you try adding this line
[self.window makeKeyAndVisible];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"FirstRegistration" bundle:nil];
FirstVC *fvc = [sb instantiateViewControllerWithIdentifier:#"FirstVC"];
self.window.rootViewController = fvc;
[self.window makeKeyAndVisible]; //**Add this**
return YES;
}

Got SIGABRT when running my first iOS app

Trying to write my first iPhone application using Xcode 5.1. Here is part of my AppDelegate code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"AddViewController"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.viewController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
I have a storyboard called "Main.Storyboard" with Navigation Controller and View Controller.
When I run my app I get SIGABRT error with NSInternalInconsistencyException exception.
Could anyone help me to fix this error?
Thanks.
why you adding subview as a UINavigationController.view and root-view as a view-controller? Your code must be look like this:-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"AddViewController"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
And verified that identifier of your viewcontroller is setting correct or not that you are given in above.
Try this
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyBord = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:[NSBundle mainBundle]];
self.window.rootViewController = [storyBord instantiateInitialViewController] ;
[self.window makeKeyAndVisible];
return YES;
}
If you use storyboard as a main interface you don't need to setup any code. So you can add UINavigationController to the scene in you storyboard. Then set rootViewController using connection inspector.
Check the video for understanding: link
the code will look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}

Enable JASidePanels in only one viewController

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];
}
}

iOS unable to load views

I am trying to navigate from one view to another on touch of a button using iOS 5.0.
The code I am using
- (IBAction)Actionlogin:(id)sender {
NSLog(#" login button has been pressed");
NSLog(#"In init");
test_details *aSecondPageController=[[test_details alloc]initWithNibName:#"test_details" bundle:nil];
[self.navigationController pushViewController:aSecondPageController animated:NO];
}
I have two xib files test_details_iPhone.xib and test_details_iPad.xib
Inside my testdetails.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSLog(#"it is coming here in second view");
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
NSLog(#"it has been returned ");
return self;
}
LOGs
2013-04-25 11:06:17.191 app_gototest[3067:207] login button has been pressed
2013-04-25 11:06:17.194 app_gototest[3067:207] In init
2013-04-25 11:06:17.195 app_gototest[3067:207] it is coming here in second view
2013-04-25 11:06:17.196 app_gototest[3067:207] it has been returned
The view is not getting loaded onto the view. I suppose I am missing something.
application:didFinishLaunchingWithOptions: in appDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
** I am trying Jasper Blue's approach**
argc int 1
argv char ** 0xbfffed2c
*argv char * 0xbfffee44
In appDeleagte.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController* navigationController;
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
}
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
You code looks OK, so it must be that self.navigationController is nil. . . Have you set up a navigation controller?
For your code to work, your current UIViewController needs to be contained within a UINavigationController. . . you can set up the UINavigationController as the root view controller in your application delegate as follows:
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController* navigationController;
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
navigationController = [UINavigationController alloc] initWithRootViewController:viewController];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
navigationController = [UINavigationController alloc] initWithRootViewController:viewController];
}
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
NB: You could clean the above code up a little, but you get the picture, which is that you have to set the root view controller to be a navigation controller, like this:
self.window.rootViewController = navigationController;
You could also make a custom root view controller if you like, but the above will let you achieve what you're trying to do - UINavigationController will be used as the navigation system throughout your app.
Your navigation controller is nil. So replace your didFinishLaunchingWithOptions method with
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
UINavigationController *navcontroller = navigationController = [UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navcontroller;
[self.window makeKeyAndVisible];
return YES;
}
Now you have a navigation controller so the call to push method on the self.navigationController should push the second controller.
Please try
- (IBAction)Actionlogin:(id)sender {
NSLog(#" login button has been pressed");
NSLog(#"In init");
test_details *aSecondPageController=[[test_details alloc]initWithNibName:#"test_details_iPhone" bunndle:nil];
[self.navigationController pushViewController:aSecondPageController animated:NO];
}
// test_details_iPhone.xib and test_details_iPad.xib
//Change initWithNibName#"test_details" with test_details_iPhone or test_details_iPad

login view does not load before main ViewController in Xcode 4

Here is the layout of my app.
ApplicationName
LoginViewController.h
LoginViewController.m
LoginView.xib
AppDelegate.h
AppDelegate.m
ViewController.h
ViewController.m
ViewController_iPhone.xib
ViewController_iPad.xib
Currently in my AppDelegate.m I have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
LoginViewController *_loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginView" bundle:[NSBundle mainBundle]];
self.loginViewController = _loginViewController;
[_loginViewController release];
[_window addSubview:[loginViewController view]];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
} else {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
My LoginView.xib has it's File's Owner defined as LoginViewController.
I was at first getting an error stating: reason: '-[UITableViewController loadView] loaded the "LoginView" nib but didn't get a UITableView.'"
I changed UITableViewController to UIViewController and I was able to run the app without an error. The only problem now is that my LoginViewController does not load. I see the blank grey ViewController_iPad.xib loading.
What am I missing here?
I can post up any other code that would be useful.
Thanks in advance!
You should be setting your window's root view controller to self.loginViewController.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginView" bundle:[NSBundle mainBundle]];
[self.loginViewController release];
self.window.rootViewController = self.loginViewController;
[self.window makeKeyAndVisible];
return YES;
}

Resources