(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.
Related
I make an application using Tab Bar.
I have 2 views controller: View1 and View2 and a RootViewController.
In RootViewController.m:
- (void)viewDidLoad
{
[self.navigationItem setTitle:#"Tab Bar"];
View1 *vc1 = [[View1 alloc]init];
View2 *vc2 = [[View2 alloc]init];
[vc1.tabBarItem setTitle:#"View1"];
[vc2.tabBarItem setTitle:#"View2"];
[self setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil]];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
When I build application, I have an error: Have a white place. When I go to View 2 and back to View 1 it is disappeared. I want to delete white place. Please see image in here: http://photo.ssc.vn/images/108Screen_Shot_2013_08_18.jpg
Thanks for your helping!
This is a common issue when adding view controllers to a tab bar.
The solution is to set wantsFullScreenLayout on the UINavigationController to NO, so it won't even attempt to leave that gap for the status bar.
Apple says :
Tab bar controllers support full-screen layout differently from the
way most other controllers support it. You can still set the
wantsFullScreenLayout property of your custom view controller to YES
if you want its view to underlap the status bar or a navigation bar
(if present). However, setting this property to YES does not cause the
view to underlap the tab bar view. The tab bar controller always
resizes your view to prevent it from underlapping the tab bar.
For more detailed explanation you can see this Question.
I'm looking for a way to have a navigation bar not show up on a screen at all.
I know there is a setNavigationBarHidden:animated: to use on the navigationbar, but this still shows the bar on the screen for a split second before removing and readjusting the screen dimensions.
I've tried moving the setNavigationBarHidden:animated: to the viewDidLoad:, viewWillAppear: etc. and set it hidden on the previous activities viewWillDisappear: but it will shows up on the next screen.
How do I make it such that the view loads with out a navigationbar on it before it is shown?
Thanks,
Dman
I'm hiding the navigation bar for the UINavigationController in the AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method and works fine for me. At some point, while navigating through the screens, I'm showing it then hide it again. Works like a charm.
UIViewController *controller = [[UIViewController alloc] init];
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController: controller];
navCtrl.navigationBarHidden = YES;
self.window.rootViewController = navCtrl;
[controller release];
[navCtrl release];
Hope this helps.
P.S. Actually I never show the navigationBar of the navigation controller again. On the controllers that need the bar I'm adding a new one.
You could try and do
setNavigationBarHidden:animated:
in your view which is calling the view where you don't want it to be displayed just before you call your new view. If they have the same navigationcontroller, it should already be hidden if it appears
if not, you try to set it on the navigation oder viewcontroller before your present it...
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;
}
I have created an empty project (XCode 4.2 IOS SDK 5), I have added a new view to it and make it the root view controller inside the appDelegate, so when the app runs, it displays that view correctly, however, I added a tabbarcontroller to the view, created an IBOutlet for it inside the newly created view, and added this line to viewDidLoad method of the view:
[self.view addSubview:self.tabController.view];
so the tab bar loads correctly in the iphone simulator, but with a little problem that I couldn't fix: half of that tab bar is shifted down the simulator which prevents tabs' titles from appearing, exactly as in the following screenshot:
How can I fix this problem?
Most likely it's because of status bar. But, because subview where you inserting controller can be any size, most universal solution is:
[tabController.view setFrame:self.view.bounds];
(assuming self.view - is the view, where you adding it)
The view with the tab bar on is 480px high, but the view you're adding it to is smaller than that because of the status bar. This means that it starts 22px too low, and ends 22px too low - off the bottom of the screen.
If you want the tab bar to be global to the app link it to an IBOutlet on the app delegate, then do this in your didFinishLaunching method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...
// Add the tab bar controller's view to the window and display.
[window addSubview:tabController.view];
[window makeKeyAndVisible];
return YES;
}
This adds it to the main window, rather than another view. This will anchor it to the top of the screen, so the bottom will be at the bottom of the screen.
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.