Unexpected space between status bar and application ios 7 / 8 - ios

I'm trying to use onboarding library start the app, I'm not using any navigation controller this is my didFinishLaunchingWithOptions function
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
_mobileOnboardVC = [[MobileOnboardViewController alloc]init];
_onboardVC =[_mobileOnboardVC loadOnboard];
_onboardVC.view.frame = [[UIScreen mainScreen] applicationFrame];
self.window.rootViewController = _onboardVC;
[self.window makeKeyAndVisible];
return YES;
And I'm getting this screen, can anyone point me out what's wrong with my code? Thank you

I'm not sure from your code what you are using as a navigation system, but that appears to be a navigation bar on the screen and you can remove that by doing the following:
in your viewdidload of the view controller you are presenting, just type this:'
[self.navigationController.navigationBar setHidden:TRUE];
You should also put this in your viewWillAppear in the same viewcontroller so that when the page is loaded from a "back button" press, this bar is removed as well.
So, this:
- (void)viewDidLoad {
[super viewDidLoad];
[[self navigationController] setNavigationBarHidden:TRUE];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:TRUE];
}

It's the background picture I'm using causing this problem. I'm using a big picture for the content image, the gap should be part of my background image. To solve this, I need use a small image like an icon as page content, then it will work.

Related

iOS 7 statusbar overlapping content [duplicate]

This question already has answers here:
iOS 7 - Status bar overlaps the view
(14 answers)
Closed 8 years ago.
I am having a rather trivial example, where I compose a pretty simple layout:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
self.window.rootViewController = self.someController;
...
Now the problem is, that the content of my viewcontroller is below the statusbar (20px).
Is the recommended way to manually resize my viewcontroller and move it 20px to the bottom, or is there any smarter way of handling this?
Note: I do not want to use e.g. UINavigationController.
[edit]
To clarify, some more code:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.menuController = [[MenuController alloc] init];
CalendarViewController* center = [[[CalendarViewController alloc] init] autorelease];
IIViewDeckController* rootController = [[IIViewDeckController alloc] initWithCenterViewController:center leftViewController:self.menuController];
rootController.leftLedge = [[UIScreen mainScreen] bounds].size.width - 320.0;
rootController.delegate= self.menuController;
self.window.rootViewController = rootController;
[self.window makeKeyAndVisible];
}
As you can see, I'm using the IIViewDeckController (Link) as root controller. Currently it looks like this:
Use this code in viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
if([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout=UIRectEdgeNone;
}
Please let me know if you are still facing the same problem.
The correct way to do this is to align all your views to the topLayoutGuide of the view controller. The layout guide will handle pushing your views down for the status bar, the in-call bar and if you move to a navigation controller later.

The imageView has been obstructing by navigationItem

I found some sample code.
It show the view by following code in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
NSLog(#"AppDelegate didFinishLaunchingWithOptions");
application.applicationIconBadgeNumber = 0;
}
AITPreviewViewController *previewViewController = [[AITPreviewViewController alloc] initWithNibName:#"AITPreviewViewController" bundle:nil];
navigationController = [[UINavigationController alloc]initWithRootViewController:previewViewController];
[self.window setRootViewController:navigationController] ;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
The following picture is in the AITPreviewViewController.xib.
But the View is not normal when it run on the iPhone , it show like the following picture.
The three imageView on the top has been obstructing by navigationItem
But when I turn to other View , and use the following code to turn back.
UIViewController *Previewer = [[AITPreviewViewController alloc] initWithNibName:#"AITPreviewViewController" bundle:nil] ;
Previewer.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController pushViewController:Previewer animated:YES];
It show the normal View like the following picture.
The View only show not normal at first time...
What happened to this condition ?
Can it use Auto-layout to solve this problem ?
If you don't want to hide navigation bar then in your xib just make a little change
Just change the Top Bar property from none to as shown in image. It will auto place your image below the navigation bar
Try increasing the 'Y' value for those 3 images from your interface builder. Select each image and then go to Size Inspector. There you will see some values. Find the Y value and increase it. This will push the images down.
If you want to show only UI according to "AITPreviewViewController.xib"
Then you can hide your navigation bar.

Adjusting uitableview height

I'm creating a simple application with uitableview. I want to create everything in code. I used following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FBVCalendarViewController *calendarViewController = [[FBVCalendarViewController alloc] init];
self.window.rootViewController = calendarViewController;
[self.window makeKeyAndVisible];
return YES;
}
...
- (void)loadView
{
UITableView *calendarItems = [[UITableView alloc] init];
self.view = calendarItems;
}
it works, but application fills the entire phone screen intersecting with standard phone title bar.
What is the right way to adjust view height?
Since UITableView inherits from UIScrollView, you should take care of the changes appeared with IOS 7.
A solution to your problem is:
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
[self setNeedsStatusBarAppearanceUpdate];
self.automaticallyAdjustsScrollViewInsets = NO;
}
(this will keep the table view below the status bar).
Hope that helps. But you should probably have a look at changes introduced with IOS 7.
So I solved my problem with the following code in loadView:
- (void)loadView
{
UITableView *calendarItems = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
UIView *rootView = [[UIView alloc] init];
[rootView addSubview:calendarItems];
self.view = rootView;
}
I used empty UIView as a parent for tableView and changed constructor to explicitly specify UITableView frame. I think that better approach would be to use autolayout (currently it just does not work as expected when I rotate device) and position table view to the full screen or implement device rotation callback and update frame there.

Switch between different Views with a Navigation Controller

I'm totally new to iOS programming. I only programmed on Android so far and Objective-C is a total different and new language for me now.
What I want to do is to not use a design that I've created with the storyboard. I want to do all programmatically, since I think it will be more dynamic if I do it like this.
The problem I'm encountering is, that I want to have 3 different views. I googled a bit, and stumbled upon some stackoverflow questions. There, people suggested using a NavigationController. Okay. Now I'm trying to implement it. What I want to have is the following
A MainViewController that has 3 different views. The first view is a loginView. The second one is displaying data and the third is displaying detailed data dependent on the click of the second view.
Is a navigationcontroller corerct for this? The problem I'm having is where I tell the app that I want to start with the MainViewController and push the LoginView in it.
I have a MainViewController.h and MainViewController.m that are subclasses of UIViewController
Now, where exactly do I do this? I have the didFinishLaunchingWithOptions method right here with the following content
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
UIViewController *viewController = [[MainViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[navigationController pushViewController:viewController animated:NO];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
But that just crashes the app. What am I doing wrong? How do I get those three views? Am I starting completely wrong? Please help. As I said I'm new to iOS development. It's easy for me to programm on one view. I did that already, but I want thre different views! Thanks!
A MainViewController that has 3 different views. The first view is a loginView. The second one is displaying data and the third is displaying detailed data dependent on the click of the second view.
That's wrong.
You need three different view controllers, each of those will manage its own view.
Then you push one after another in the navigation controller, depending on user interaction.
Yes, Gonzalo Aune is rite, You should not push the rootviewcontroller in NavicationController.
Also , I will Suggest you to keep your first view (Login View) out of Navigation controller.
You can start with your MainViewController and based on check and conditions you can present LoginView on MainViewController using
[self presentViewController:loginViewController animated:YES completion:NULL];
And after successful login you can dismiss LoginViewController.
Remove this:
[navigationController pushViewController:viewController animated:NO];
You shouldnt push the ViewController since you told the NavigationController already that the ViewController would be the root one:
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:viewController];
use this code and if application is universion then use same code else remove the condition of ([[UIDevice currentDevice] userInterfaceIdiom]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *navController;
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];
{
if(result.length>0)
{
for(var i in result)
{
var ObjResult=result[i];
var content = "<div data-role='collapsible' id='set" + i + "'>";
content+="<h3>"+ObjResult.title+"<br>";
var intDate=parseInt(ObjResult['ordered date']);
content +=timestampToDate(intDate)+"</h3>"
if(isNaN(ObjResult.med_placeorderfor))
content+="<p><a>Medicle Place order for: </a>"+result[i].med_placeorderfor+"</p>";
if(isNaN(ObjResult.pres_placeorderfor)>0)
content+="<p><a>Medicle Place order for: </a>"+result[i].placeorderfor+"</p>";
if(ObjResult['order status'].length>0)
content+="<p><a>Order status: </a>"+ObjResult['order status']+"</p>";
if(ObjResult.comments.length>0)
content+="<p><a>Comments: </a>"+ObjResult.comments+"</p>";
content+="</div>";
}
$("#id_notification_list_dashboard").append( content ).collapsibleset('refresh');
$("#id_notification_list_dashboard").trigger('create');
}
else
{
$("#id_notification_list_dashboard").append("<div style=\"text-align:center\" data-role='list-divider'><h1>No data found</h1></div>").collapsibleset('refresh');
}
$('body').removeClass('ui-loading');
loadingWithMsg("hide");
}
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
navController=[[UINavigationController alloc]initWithRootViewController:self.viewController];
[navController.navigationBar setTranslucent:YES];
navController.navigationBar.tintColor = [UIColor colorWithRed:161.0f/255.0f green:18.0f/255.0f blue:6.0f/255.0f alpha:1];
self.window.rootViewController =navController ;
[self.window makeKeyAndVisible];
return YES;
}

UINavigationBar is smaller than it has to be

I'm developing an app and I have a sing-in/sign-out process. When the user clicks in the sign-out button I want the user to be taken to the home screen. To do this I created the following method in the app delegate:
- (void) restartAppWhenLogOut{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
WelcomViewController *welcomeViewController = [[WelcomViewController alloc]init];
self.navController = [[UINavigationController alloc] initWithRootViewController:welcomeViewController];
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
}
When the user clicks the "Log out" button I call this:
[[UIApplication sharedApplication].delegate restartAppWhenLogOut];
And it works fine except for one thing. The UINavigationBar is smaller than it should be! Here is an screenshot of how it looks:
There is an small black line that should be filled by the UINavigationBar...
Any idea why this is happening?
=======================================Edit=======================================
I removed the new windows creation as David M. told me to do in one comment but It still fails:
[self.navController popToRootViewControllerAnimated:NO];
WelcomViewController *welcomeViewController = [[WelcomViewController alloc]init];
self.navController = [[UINavigationController alloc] initWithRootViewController:welcomeViewController];
[self.window setRootViewController:navController];
I tried to figure out the error..but didn't find out..so, i suggest you try to setting up the navigation bar manually..
Creating a new window is forbidden: "To change the content your app displays, you can change the window’s root view; you don’t create a new window." UIKit isn't intended to work that way.
Following json advice this is what I did in the viewDidLoadof the view controllor with the UINavigationBar problem:
[self.navigationController.navigationBar setFrame:CGRectMake(0, 20, 320, 44)];
I hope it helps!

Resources