JASidePanel : Need to maintain permanently a menu to the left - objective-c

I'm studying the JASidePanel stackController.
But I would like to know if there is a possibility to maintain permanently a menu to the left of the screen independently of the JASidePanel.
In order to do that, I have tried to insert the JASidePanelController as a subview of an other UIViewController like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// My part ---------------------
UIViewController *rootViewController = [ [ UIViewController alloc ] init ];
UIView *rootView = [ [ UIView alloc] initWithFrame:CGRectZero ];
rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth + UIViewAutoresizingFlexibleHeight;
[rootView setBackgroundColor:[UIColor yellowColor]];
rootViewController.view = rootView;
// ---------------------
JASidePanelController *sidePanelController =[[JASidePanelController alloc] init];
sidePanelController.leftFixedWidth = 260;
self.viewController = sidePanelController;
self.viewController.shouldDelegateAutorotateToVisiblePanel = NO;
self.viewController.leftPanel = [[JALeftViewController alloc] init];
self.viewController.centerPanel = [[UINavigationController alloc] initWithRootViewController:[[JACenterViewController alloc] init]];
self.viewController.rightPanel = [[JARightViewController alloc] init];
self.viewController.view.frame = CGRectMake(61, 0, self.viewController.view.frame.size.width, self.viewController.view.frame.size.height );
[ rootView addSubview:self.viewController.view ];
// My part ---------------------
self.window.rootViewController = rootViewController;
// ---------------------
[self.window makeKeyAndVisible];
return YES;
}
It works but I am not fully satisfied.
Indeed, when I swipes my finger to the left, in order to show the right panel, the center panel don't move correctly to the left and covers my personal menu (in yellow).
As a result, the right panel is not visible totally and my menu (in yellow) is not visible.
Please, have a look to my illustrations to understand what I want to do.
Is anyone have a idea of how to do that?
Many thanks per advance!

Related

UITextField keyboard dismiss on button click to UIApplication method

I'm going from storyboard to UISplitViewController in a xib. I want to logout of my storyboard view, which will bring me to the UISplitViewController. In the storyboard controller, I have a UITextField. I set it so that it doesn't dismiss itself after I press enter. However, it now stays open even when I switch to the splitviewcontroller, which I obviously don't want because i want to logout.
Logout Button
UIBarButtonItem *logoutButton = [[UIBarButtonItem alloc] initWithTitle:#"Log Out" style:UIBarButtonItemStylePlain target:self action:#selector(confirmLogout)];
Method to bring up UISplitViewCOntroller
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (alertView.tag==TAG_DEV){
if (buttonIndex) {
[[[UIApplication sharedApplication] delegate] performSelector:#selector(gotoSplitViewController)];
} else {
[self.navigationController popViewControllerAnimated:YES];
}}
}
method gotoSplitViewController in the delegate:
-(void)gotoSplitViewController{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ListViewController *listVC = [[ListViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *listNC = [[UINavigationController alloc] initWithRootViewController:listVC];
AssignedViewController *assignedVC = [[AssignedViewController alloc] initWithNibName:#"AssignedViewController" bundle:nil];
UINavigationController *assignedNC = [[UINavigationController alloc] initWithRootViewController:assignedVC];
//assign the views to the new nav view controllers
splitViewController = [[UISplitViewController alloc] init];
splitViewController.delegate = assignedVC;
splitViewController.viewControllers = #[listNC, assignedNC];
listVC.detailViewController = assignedVC;
[[self window] setRootViewController:splitViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
}
my UITextField
self.textBox = [[UITextField alloc] initWithFrame: CGRectMake(10, 660, 750, 90)];
self.textBox.backgroundColor = [UIColor colorWithRed:(209/255.0) green:(236/255.0) blue:(232/255.0) alpha:1];
self.textBox.returnKeyType = UIReturnKeySend;
self.textBox.delegate = self;
[self.view addSubview:self.textBox];
I've tried the resignFirstResponder if various places, including adding
- (void)viewWillDisappear:(BOOL)animated
{
[self.textBox resignFirstResponder];
}
However, none of them work. How do I get the keyboard to disappear after the views change?
I set
self.chatBox.delegate=nil;
in my methods to switch views

UINavigationController with UISegmentedControl in AppDelegate to switch rootviewcontroller of UINavigationController

I would like to create an app with a navigation controller as a window root view controller and a segmented control in a title view of the navigation controller to switch its root view controller
Problem: segmented control is not present after adding it to nag controller
Code:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
FirstViewController * fc = [[FirstViewController alloc] initWithNibName:#"FirstView" bundle:nil];
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:fc];
[fc release];
self.window.rootViewController = nc;
NSArray * array = [NSArray arrayWithObjects:#"GPS",#"List",#"Map", nil];
UISegmentedControl * sc = [[UISegmentedControl alloc] initWithItems:array];
sc.frame = CGRectMake(0, 0, 250, 50);
sc.segmentedControlStyle = UISegmentedControlStylePlain;
[nc.navigationItem setTitleView:sc];
[sc release];
[nc release];
[self.window makeKeyAndVisible];
return YES;
}
You are setting titleView for NavigationItem instead set Item for it.
NSArray * array = [NSArray arrayWithObjects:#"GPS",#"List",#"Map", nil];
UISegmentedControl * sc = [[UISegmentedControl alloc] initWithItems:array];
sc.frame = CGRectMake(0, 0, 250, 50);
sc.segmentedControlStyle = UISegmentedControlStylePlain;
To set in title view use this line
[ViewController.navigationItem setTitleView:sc];
To set Left or Right You can not directly add Item to Navigation bar, so create BarButtonItem with your segmentControl
UIBarButtonItem *segmentItem = [[UIBarButtonItem alloc] initWithCustomView:sc];
add it to ViewController not to NavigationController
[ViewController.navigationItem setRightBarButtonItem:segmentItem];

How to deal with storyboard instead of xib file in such case?

I have an example where I have animation when the app starts. At the start an image is displayed, then moves from right to left, then disappears. Below is the code I have.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewwController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewwController;
[self.window makeKeyAndVisible];
//add the image to the forefront...
UIImageView *splashImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[splashImage setImage: [UIImage imageNamed:#"Default"]];
[self.window addSubview:splashImage];
[self.window bringSubviewToFront:splashImage];
//set an anchor point on the image view so it opens from the left
splashImage.layer.anchorPoint = CGPointMake(0, 0.5);
//reset the image view frame
splashImage.frame = CGRectMake(0, 0, 320, 480);
//animate the open
[UIView animateWithDuration:1.0
delay:0.6
options:(UIViewAnimationCurveEaseOut)
animations:^{
splashImage.layer.transform = CATransform3DRotate(CATransform3DIdentity, -M_PI_2, 0, 1, 0);
} completion:^(BOOL finished){
//remove that imageview from the view
[splashImage removeFromSuperview];
}];
return YES;
}
What I want is to do this using a storyboard, so I changed the code as below.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MyBookViewController *myNew = [[MyBookViewController alloc] init];
self.myBookViewController = myNew;
self.window.rootViewController = self.myBookViewController;
[self.window makeKeyAndVisible];
However I don't see my viewcontroller (MyBookViewController). I only see the image moving from right to left, then a black screen.
Any idea what is going wrong?
I just did it myself with help of this SO question.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle: nil];
MyBook001ViewController *controller = (MyBook001ViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"firstStory"];
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];
i think it is because of you are allocating new MyBookViewController. instead it you have to give reference of storyboard, on which you have your UI design for MyBookViewController, like this
MyBookViewController *myNew=[self.storyboard instantiateViewControllerWithIdentifier:#"MyBookViewController"];
be sure for ViewController identifier
UPdate1:
try with
MyBookViewController *myNew=[self.window.rootViewController];

Root View Controller items are not clickable

After some great trouble, I was finally able to load my first Navigation / ViewController, only now none of the sub items are clickable. I mean, I have a two text fields, two buttons, and a switch, but none of them do anything when clicked. I know it is not a problem with my xib file, as these elements behave in the xib simulator for iPad.
This is all the code my application uses so far, and I don't see why it should not be clickable.
MainWindow.xib = empty nib file
int retVal = UIApplicationMain(argc, argv, nil,
#"iPadAppDelegate");
application: didFinishLaunchingWithOptions:
self.window = [[UIWindow alloc] init];
UIViewController *login = [[UIViewController alloc] initWithNibName:#"iPadLoginView" bundle:nil];
UINavigationController *nav_controller = [[UINavigationController alloc] initWithRootViewController:login];
self.window.rootViewController = nav_controller;
[self.window makeKeyAndVisible];
return YES;
replace your
self.window = [[UIWindow alloc] init];
with
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Replace
self.window.rootViewController = nav_controller;
with
[self.window addSubview:nav_controller.view];

Where to declare ViewControllers for a custom tab view?

I'm trying to figure out how to use a custom tab view I found called JMTabView by Jason Morrissey on GitHub. (I tried asking him directly but got no response.)
I know how to programmatically create a UITabBarController and assign view controllers. What I can't figure out is where to declare my four UITableViewControllers and other VC's for each of the four tabs in this example. The code:
// TabDemoAppDelegate.m -> do I declare them here?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
TabDemoViewController * demoViewController = [[[TabDemoViewController alloc] initWithNibName:nil bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:demoViewController] autorelease];
//[self.navigationController setNavigationBarHidden:YES];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
// TabDemoViewController.m -> or somewhere in here?
-(void)addCustomTabView; { // this is a private method
JMTabView * tabView = [[[JMTabView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 60., self.view.bounds.size.width, 60.)] autorelease];
tabView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[tabView setDelegate:self];
UIImage * standardIcon = [UIImage imageNamed:#"icon3.png"];
UIImage * highlightedIcon = [UIImage imageNamed:#"icon2.png"];
CustomTabItem * tabItem1 = [CustomTabItem tabItemWithTitle:#"One" icon:standardIcon alternateIcon:highlightedIcon];
CustomTabItem * tabItem2 = [CustomTabItem tabItemWithTitle:#"Two" icon:standardIcon alternateIcon:highlightedIcon];
CustomTabItem * tabItem3 = [CustomTabItem tabItemWithTitle:#"Three" icon:standardIcon alternateIcon:highlightedIcon];
CustomTabItem * tabItem4 = [CustomTabItem tabItemWithTitle:#"Four" icon:standardIcon alternateIcon:highlightedIcon];
[tabView addTabItem:tabItem1];
[tabView addTabItem:tabItem2];
[tabView addTabItem:tabItem3];
[tabView addTabItem:tabItem4];
[tabView setSelectionView:[CustomSelectionView createSelectionView]];
[tabView setItemSpacing:1.];
[tabView setBackgroundLayer:[[[CustomBackgroundLayer alloc] init] autorelease]];
[tabView setSelectedIndex:0];
[self.view addSubview:tabView];
}
He mentions blocks... if they're relevant, what are they and is this where I would declare the VC's? If so, how?
// You can run blocks by specifiying an executeBlock: paremeter
// #if NS_BLOCKS_AVAILABLE
// [tabView addTabItemWithTitle:#"One" icon:nil executeBlock:^{NSLog(#"abc");}];
// #endif
I'm not familiar with that particular library, but if it follows a similar pattern to UITabViewController I would create properties for your tab (if you need to reference them later) in your App Delegate's .h file and then create your instances in the .m. If you are just placing the tabs and don't need to reference them directly anymore you should be able to define them in the .m (probably in applicationDidFinishLaunching) and then assign them as tabs and let the tab controller take it from there.