Xcode: Custom TabBarController - iphone

I am creating an application that i want to have instead of the normal UITabBarController i want to make mine so it can scroll;
So i Started by creating a simple window based application and programmatically created my UITabBar and UIScrollBar set both their frames correctly and removed the self.window.rootViewController = viewController1; portion of the code so that my app shows the scrollviewwith the tabbar and not my UIViewController
So this far everithing works as expected.
the problem goes when launching my viewControllers, i currently am using:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
if (item.tag == 2) {
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self presentViewController:viewController2 animated:NO completion:nil];
}
}
the problem is that this does work but the view controller is in front of the tabbar so i can't use it to switch views again.
i have tried changing the frame of the view in the viewController so its small enough to fit the scrollview with the tab bar but it just ignores this part, so im kind of stuck here.
if anyone could point me in the right direction or tell me if im ignoring some option that i have to set will be greatly appreciated.
Thanks in advance!

Why make things difficult? just make UIButtons with custom images(images like TabBar "buttons") and put the button in a scrollview ;)

Related

Xcode 4.1 Add and View TabBarController with existing ViewController

First of all sorry for my bad english and Im pretty new in these forums and Xcode programing.
So, Im writing an IPhone app with Xcode 4.1, that has Login and Register stuff visualized with UIViewController. When Im logged in, I need to visualize TabBar with different views.
I tried a lot of stuff and watched a lot of tutorials, all of them just start with the TabBarController, but I don't need it from the beginning, I just need to call it later.
The right way I believe should be just create new file .h, .m and .xib, then add the TabBarController and do a relation between TabBarController - view and File's Owner - view... but it don't let me do this thing. Obviously it don't visualize the right window.
How is the right way to do it?
Please help me, before my hair fall off...
Use the UITabBarController as the root view controller, but display a modal registration / logon view controller over the top when the app begins.
Once the user has logged in, dismiss the modal view controller to reveal the tab bar controller below.
You just use this code in your login button click or next viewcontroller viewwillappers method
UITabBarController *tabbar1 = [[UITabBarController alloc] init];
firstViewcontroller *second = [[firstViewcontroller alloc] initWithNibName:nil bundle:nil];
second.title=#"";
SecondViewController *third=[[SecondViewController alloc]initWithNibName:nil bundle:nil];
third.title=#"";
thirdViewController *one=[[thirdViewController alloc]initWithNibName:nil bundle:nil];
one.title=#"";
tabbar1.viewControllers = [NSArray arrayWithObjects:one, second,third,nil];
tabbar1.view.frame=CGRectMake(0, 0, 320, 460);
[self.view addSubview:tabbar1.view];
I am sure it will work for you i always use this code for create tab bar in any view.

Allowing autorotation inside a programmatically created view that is displayed modally

This has been asked a dozen times on this site, but I haven't found an answer that works for me. I have an iPad application with a UISplitViewController on the root level that is created programmatically. Inside the view that is being displayed in the right hand pane, triggered by user interaction, a UINavigationController is programmatically created and presented to the user. Here is that code:
listenerController = [[UINavigationController alloc] initWithRootViewController:listenerView];
[listenerController.navigationBar setTintColor:[UIColor colorWithRed:185.0f/255.0f green:80.0f/255.0f blue:0.0f/255.0f alpha:1.0f]];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[listenerController setModalPresentationStyle:UIModalPresentationFormSheet];
[listenerController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[listenerController setModalInPopover:YES];
}
[self presentModalViewController:listenerController animated:YES];
[listenerController release];
This does create the view controller properly, but when it is displayed the iPad is forced back into portrait view regardless of what orientation I have the iPad in. Then when I dismiss the modal window, it will rotate back.
I already have shouldAutorotateToInterfaceOrientation in the viewcontroller of the righthand pane set to YES, and I even tried adding this to the main app delegate class without any luck. It doesn't seem like I should have to subclass UINavigationController just to override the shouldAutorotateToInterfaceOrientation method.
Am I calling presentModalViewController from the wrong object? I've tried [self presentModalViewController ...] as well as [self.parentViewController presentModalViewController ...] with the same results.
I'm assuming that the self in your code example is the right-view (detail) view controller. You need to call presentModalViewController from the root UISplitViewController.

Showing a modal view controller from a tab bar app

First, I would like to warn that I am a complete newbie into iPhone coding...
I need to show up a viewcontroller from a library, I know that it is modal. I have a tab bar app (created with the default XCode template). I need to show that viewcontroller, there are no problem if it hides the tabbar itself... But I am quite clueless, I don't know even what to search, or what to read...
You can call presentModalViewController:animated: to display another UIViewController modally.
EDIT: If you want to display your modal view in response to a button touch (for example), you would display it like this:
- (IBAction)buttonTouched:(id)sender
{
ModalViewController* controller = [[ModalViewController alloc] init];
[self presentModalViewController:controller animated:YES];
[controller release];
}
Then when you want to dismiss the modal controller, call dismissModalViewControllerAnimated:. This can be called either on your main view controller, or the modal one.
I don't know even what to search, or
what to read...
View Controller Programming Guide is a good place to start to help you understand view controllers (including modal ones). If that's confusing, get a bigger picture with iOS Application Programming Guide or start at the very beginning.
You can call modal view as
YourViewController *yvc = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:YES]
[self presentModalViewController:yvc animated:YES];
You can call it in the IBAction method in case you want to call it on any control event like Button Click
-(IBAction)buttonClicked:(id)sender
{
YourViewController *yvc = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:YES]
[self presentModalViewController:yvc animated:YES];
}
You can call it using self.
Hope this helps you.
If you have more doubts on this then you can ask me.

How to HIDE the iPad keyboard from a MODAL view controller?

I'm trying to hide the iPad keyboard from a modal view controller but it doesn't work. I have tried resignFirstResponder but that doesn't have any affect if we are in a modal view controller. I tried resignFirstResponder in a non-modal UINavigationController with the very same UIViewController and the keyboard hides correctly.
Does anyone know how solve this problem?
Thanks.
[Update] it looks like there's something wrong with my code because the resignFirstResponder does work (I made a simple test case instead of using my code). But I still don't know what the problem is.
Apparently, there is a new -[UIViewController disablesAutomaticKeyboardDismissal] method that you may override to solve this problem in iOS 4.3.
It was because I was using UIModalPresentationFormSheet. All of the other ones work as expected.... Wasted several hours on that.
This was a total pain to find. Seems like one of the poorer API designs in iOS. Much appreciation to #0xced and #manicaesar for the answers.
Here's my consolidated answer for future devs who are stuck beating their head against the wall.
If it's a single view controller, just override disablesAutomaticKeyboardDismissal and return NO.
If it's a navigation controller in a modal, create your own UINavigationController subclass like so:
In .h...
#interface MyNavigationController : UINavigationController
#end
In .m....
#implementation MyNavigationController
#pragma mark -
#pragma mark UIViewController
- (BOOL)disablesAutomaticKeyboardDismissal {
return NO;
}
#end
In your code that shows a modal view controller.
UIViewController *someViewController = [[UIViewController alloc] init];
MyNavigationController *navController = [[MyNavigationController alloc] initWithRootViewController:someViewController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:YES];
I just confirmed the problem is indeed UIModalPresentationFormSheet and filed a bug report to apple rdar://8084017
I solved this by resizing a UIModalPresentationPageSheet. See my answer here.

TableView To Navigation Controller on the View-Based Application Project?

I built an application. On the one my views I used TableView. So now I want to change this Table view to a navigation controller.
1- How can I change UITable view to Navigation Controller.؟
The easiest way to achieve this is to create a new 'Navigation-based Application'. This will set up everything you need. By default this will set you up with simple RootViewController, if you want you can change this to be your TableViewController by editing the application delegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];
rootViewController.managedObjectContext = self.managedObjectContext;
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
All you need to do is copy your TableViewController into the new project and change the RootViewController to be yours
If you have started with one of the template project in XCode find the .xib file for your view and launch InterfaceBuilder by double clicking the .xib file. You can manipulate the view directly by dragging and dropping components as well as adding components from a palette.
I would walk through one of Apples tutorials and get a feel for working with InterfaceBuilder - this tutorial shows adding a view controller.
Thank you everybody . finally i figured out :D , just put this code :
UINavigationController *myNav=[[UINavigationController alloc] initWithRootViewController:[[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil]];
[self presentModalViewController:myNav animated:YES];