How to Deselect tab when application is loaded - iphone

I am working on tabbar application. When application started, by default first tab is selected.
What I want to is when I start application, tab bar should be displayed without selected tab. Like say, if i have 4 tabs then non them get selected when application get launched. By default first one get selected.
I want to display some views which are not part of any of tabs.
Is it possible to do ?
Thanks...

Yes, this is possible.
You need to create a view programmatically and add that view in Window as SuperView , when you don't need it just remove it form SuperView.
[SuperViewname removeFromSuperView];
Code Snippet:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the tab bar controller's view to the window and display.
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
**AdditionalView**
//======================= LoginView ================================================
loginview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
imgview_logingpage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
imgview_logingpage.image=[UIImage imageNamed:#"Screen.jpg"];
loginview.backgroundColor=[UIColor blackColor];
[self.window addSubview:Viewnavigation.view];
[self.window addSubview:loginview]; // To add the View in Window View
}
// To REmove the View from SuperView
-(void)login_clicked:(id)sender
{
Homepage *obj_homepage=[[Homepage alloc]initWithNibName:#"Homepage" bundle:nil];
[self.window addSubview:obj_homepage.view];
[loginview removeFromSuperview];
[loginview release];
}
Or either the more easy way is : Open a new view via PresentModalViewController

If you have a visible tabBarController, then something will necessarily be selected. No way around this.
However, if you would like to hide the tabBar, then you can certainly do that, either by setting its hidden property to YES or by presenting a modal view on top of the selected tab (e.g. the first viewController).

Yes it is possible to display views that are not part of one of the view controllers managed by the tabbar controller. There are many way to do that.
You can present a view controller modally, or just add a subview in the tabbar controller's view.
But as long as the tabbar controller get instanciated, there are no way to deselect every tab.

Related

Adding a floating view to my app

My application uses UITabBarController to present 3 tabs, each tab has a UINavigationController that manag all the view controllers.
What I want to do is to add a view that will be "floating" above all views.
For example suppose I want to show my logo at the top-left corner of the screen, and I want this logo to stay on screen no matter where the user navigates, no matter witch tab he is on.
I suppose I need to add this logo to the UIWindow? I just wonder what is the best practice for doing it?
Dont add anything to the Window other than the navigation controller,or root controller. Trust me you will run into memory issues if you do this as Window isnt released but View Controllers are.
Add that floating view to to each view controller and put it as the last item in the list of subviews. You can design it once in IB or progmatically and duplicate it on each screen. This is the approach i always take and your suggested idea doesn't save you any time.
Indeed, a good place to place it is in the window just when the app launches. E.g.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//...
//... Setup root View Controller
UIView *extraView = [[UIView alloc] initWithFrame:CGRectMake(0,0,10,20)];
[extraView setBackgroundColor: [UIColor greenColor]];
[self.window addSubView: extraView];
return YES;
}

Load different view controllers inside UIView (Like iFrame for Xcode)

I am in the process of making my first iPhone app with storyboard in Xcode and am stuck. My main screen has a view controller called MemberViewController, which is the home screen. This screen has a UIView that is smaller than the view controller called mainContent.
So basically, I want to be able to load different view controllers (all the same size as the UIView) inside the UIView.
MemberViewController (home page)
-mainContent (UIView)
GetStartedViewController (separate view controller that I want to show inside the UIView)
ProfileViewController (separate view controller that I want to show inside the UIView)
For example, I want the GetStartedViewController to have a button that I can press to switch to the ProfileViewController. The view controllers need to be able to replace each other inside the mainContent UIView.
Thank you so much in advance for your help. If there's an easier way to do this, please let me know.
I use this technique a lot actually. My typical setup of a root UIViewController (you call it memberController) has a view with a UITabBar at the bottom, and then another UIView (you call it mainContent) which contains the rest of the space above that bar.
memberController stays on the screen all the time. Inside of mainContent, add a UINavigationController and initialize it with your first content-carrying GetStartedViewController. When you want to switch tabs on your tab bar, send the appropriate message to this UINavigationController and the views will change inside.
HINT: say your UINavigationController is called navController - you can get rid of the navigation bar (blue one at the top) by sending the message [navController setNavigationBarHidden:TRUE];
EDIT: The code you requested looks like this. This adds a nav controller to a window's view in the applicationDidFinishLaunchingWithOptions method. Instead of window, just do this same thing on your view controller in the viewDidLoad.
window and navController are both properties
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.navController = [[UINavigationController alloc] initWithRootViewController:[YourViewController new]];
[self.navController setNavigationBarHidden:YES];
[self.window addSubview:self.navController.view];
[self.window makeKeyAndVisible];
Hope this helps!

UITabbar controller with other views ,not with main window in iphone using monotouch

Can we create tabbar controller with any window of application? I am having knowledge of creating with main window only ..which is landing page of application..Please any body solvemy prob..Thank u..
No, you cannot add the UITabBarController on other view controllers (if that is what you mean by "any window"). It is meant to be the root controller of your app. If you add it to other controllers, it will not behave correctly.
You cannot add it to any other controllers but you can add it in MainWindow and make it appear and function in few ViewControllers only and not in the whole app. Add the UITabBarController in the AppDelegate and define it. Now, if you don't want tab bar from first in your app, you will have a navigation controller added as subView in the main window like this:
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
Now when you move to other controller and you wish to make the tab bar controller appear then you will have to remove the navigationController from the subView and add the Tab Bar controller to the subview. To do so make a separate method in AppDelegate:
-(void)Load_tabBar
{
[self.navController.view removeFromSuperview];
[self.window addSubview:tabBarController.view];
[self.window makeKeyWindow];
}
to remove the tab bar again do the reverse in another method:
-(void)remove_tabBar
{
[self.tabBarController.view removeFromSuperview];
self.tabBarController.selectedIndex=0;
[self.window addSubview:navController_initiale.view];
[self.window makeKeyWindow];
}
This will do the job for you!

How to implement a view to be shown before a Tab Bar Controller?

I am designing an iPhone app in which when the application first launches, it should show a login/password view that is not part of Tab Bar Controller. Once the user enters a valid password, they are taken to a standard Tab View with a Tab Bar as the root controller. My challenge is whether to do a Window-based application or to do a Tab Bar application when I first start the project.
I hope I am making sense.
Thank you
You can start with a Tab Bar app just fine.
In your appDelegate's application:didFinishLaunchingWithOptions: method, right at the end, you'll add the login screen's viewController and pop it up on top of the tabs by simply adding two lines, like so:
[window addSubview:tabcontroller.view]; // Already present
initialScreenViewController = [[InitialScreenViewController alloc] init];
[window addSubview:initialScreenViewController.view];
[window makeKeyAndVisible]; // Already present
return YES; // Already present
Because you're adding the initialScreenViewController (call it whatever you want, that's just an example) after the tab bar, it will appear above it (closer to the screen) in the window. When you're done with it you can dismiss it and your tabs and such will all be present.
Edited to add
Here's how to add it modally:
Instead of
[window addSubview:initialScreenViewController.view];
use
[self.tabBarController presentModalViewController:initialScreenViewController animated:NO];
[initialScreenViewController release];

View position is too high

(In the application start up event, I added my main view to app's Window in the following codes:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
MyViewController* vc = [[MyViewController alloc]
initWithNibName:#"MyViewController_iPhone"
bundle:nil];
[window addSubview:[vc view]];
[vc release];
[window makeKeyAndVisible];
return YES;
}
In my MainWindow.xib, there is no view there. It is just an empty window. MyViewController contains a navigation bar and a table. In IB, both main and my view controller has status bar at the top and my view is filled to its max view.
The issue I have is that half of my navigation bar is covered by status bar (in simulator):
I could adjust my view navigation bar lower a bit, but I don't think that's the right way to do it. Not sure if there is any way in IB or in codes to let the added view to Window is filled with the consideration of status bar?
By the way, I am using XCode 3.2.4 and iPhone 3.2 for my app.
Are you animating in the status bar? Chances are, the view is created before the status bar is unhidden, so the view's frame is setup showing full screen. Later, when the status bar is animated in, the view is not automatically resized.