Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-14-2010, 07:40 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 13
Default Top of View Cut Off (under status bar, interface builder)

On this, my first iPhone project after 30+ years of C++, ever since I went through the tutorial "Your First iPhone Application", the top of my view has been cut off, hidden under the status bar. Meanwhile, the bottom of the screen has a blank area not covered by my test background color. I followed all the tutorial instructions; used Interface Builder. In Interface Builder, the view with test-colored background, appears correctly BELOW the status bar, and fills the whole screen. When run in the simulator or on a device, however, the view is Y pixels higher, hiding partially under the status bar and not filling out to the bottom of the screen.

I didn't do any special X,Y positioning of the view. I would have thought that Interface Builder would have positioned things correctly relative to the status bar, and I would have thought that the tutorial provided code snippets that did things appropriately as well.

It seems to me that I need to compensate by moving the view down. However, I shouldn't need to do this, having followed the tutorial. So I'm wondering what I'm missing.

Just in case, here's my appdelegate code that creates the view controller. Also, there's no special code in the view controller itself, that would be germane to this question.

...

// Create main view controller
mainViewController = [[MainViewController alloc]
initWithNibName:@"MainViewController" //forum note, can't get this to indent right on forum
bundle:[NSBundle mainBundle]]; //forum note, can't get this to indent right on forum
[self setMainViewController:mainViewController];

// Setup the main view
[window addSubview:[mainViewController view]];

...

[window makeKeyAndVisible];
Please advise as to what I'm missing. I searched the forum but couldn't find any comments on this. (Hey, it's happening to everyone and nobody's mentioning it! I don't think so. I must have done something wrong...)

Thanks,
Dr.Lightning

Last edited by Dr.Lightning; 02-14-2010 at 07:42 PM.
Dr.Lightning is offline   Reply With Quote
Old 02-15-2010, 05:05 AM   #2 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

welcome to the iphone! im 14 and been on the platform for about a year. I only wish I had your background knowledge. =)

If you post the entire project on here I'm sure someone on here will be able to find the issue and explain why its happening.

Did you move the view up or down at all in code or interface builder?

Did you change the orientation or toggle the status bar?

What tutorial are you referring to btw?



All the best,
TTC
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 02-15-2010, 06:04 AM   #3 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Surely you could just make the MainViewController in a file, this is done by default.

And then that's a fullscreen thing.
ZunePod is offline   Reply With Quote
Old 02-15-2010, 01:45 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 13
Default

Quote:
Originally Posted by TapTouchClick View Post
Did you move the view up or down at all in code or interface builder?

Did you change the orientation or toggle the status bar?

What tutorial are you referring to btw?
I started with the tutorial at
iPhone Dev Center: Your First iPhone Application: Tutorial Overview and Design Patterns

I did not explicitly change ANYTHING regarding the view location, orientation, or status bar. This view location problem is how things came "out of the box" from interface builder and following the tutorial.

I'd like to know why this happened and correct it, rather than overriding the situation by explicitly moving the window.
Dr.Lightning is offline   Reply With Quote
Old 02-15-2010, 02:59 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 13
Default

I'm convinced that the Hello World tutorial has an error in it.

Can somebody else please do the following:

1) Begin by following the tutorial at:
iPhone Dev Center: Your First iPhone Application: Introduction

2) By the time you finish the "Inspecting the Nib File" page (5th page), when you run the app in the simulator you'll see a purple background.

3) However, there's a white bar below the purple background. Go back to interface builder and add label text at the very top left and bottom right corners of the MyViewController.xib view. Now when you run the simulator, you find that your top left text is under the status bar, and the bottom right text is above the white bar.

4) Further go back and use the interface builder on the MainWindow.xib that's still white. Add top left and bottom right text to it as well. (I used 48 point so it's tall enough to both position at the very top of the view, as well as later hang down partially below when it's hidden under the status bar.) Run the simulator. You'll see that the white bar at the bottom of the screen is the MainWindow showing at the bottom, and the bottom right text shows as well.

5) Therefore, the purple MyViewController view is positioning under the status bar, and is only high enough assuming it's NOT positioned under the status bar. Therefore, it ends up short, not reaching the bottom of the screen. As a result, you can still see the MainWindow view under it.

I don't think I'm doing anything wrong. Perhaps folks don't notice this when they later have a white background and don't position hello world stuff right up against the edges of the screen.

Code:
//
//  HellowWorldViewAppDelegate.h
//  HellowWorldView
//
//  Created by Helmut Forren on 2/15/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <UIKit/UIKit.h>

@class MyViewController;

@interface HellowWorldViewAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
	MyViewController *myViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) MyViewController *myViewController;


@end
Code:
//
//  HellowWorldViewAppDelegate.m
//  HellowWorldView
//
//  Created by Helmut Forren on 2/15/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "MyViewController.h";
#import "HellowWorldViewAppDelegate.h"

@implementation HellowWorldViewAppDelegate

@synthesize window;
@synthesize myViewController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    
	MyViewController *aViewController = [[MyViewController alloc]
										 initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
	[self setMyViewController:aViewController];
	[aViewController release];

	
    UIView *controllersView = [myViewController view];
    [window addSubview:controllersView];
	
    // Override point for customization after application launch
    [window makeKeyAndVisible];
}


- (void)dealloc {
	[myViewController release];
	[window release];
    [super dealloc];
}


@end
Code:
//
// Prefix header for all source files of the 'HellowWorldView' target in the 'HellowWorldView' project
//

#ifdef __OBJC__
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
#endif
Code:
//
//  main.m
//  HellowWorldView
//
//  Created by Helmut Forren on 2/15/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {
    
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}
Code:
//
//  MyViewController.h
//  HellowWorldView
//
//  Created by Helmut Forren on 2/15/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface MyViewController : UIViewController {

}

@end
Code:
//
//  MyViewController.m
//  HellowWorldView
//
//  Created by Helmut Forren on 2/15/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "MyViewController.h"


@implementation MyViewController

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
I didn't include the .xib XML because it makes the post too long for the forum software to accept.
Dr.Lightning is offline   Reply With Quote
Old 02-15-2010, 03:02 PM   #6 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

which tutorial should i go through? =p
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 02-15-2010, 03:06 PM   #7 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Smile

I've just looked at both, and honestly, i haven't had very good luck with apple tutorials in the past. I would check out others, like icodeblog, or youtube.

give those a try and I think you will have less problems.
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 02-15-2010, 03:11 PM   #8 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 13
Default

Note that adding

Code:
	aViewController.wantsFullScreenLayout = YES;
after aViewController is assigned (allocated) causes the MyViewController purple background to continue to the bottom of the screen, covering up the white of MainWindow. However, it does NOT reposition (move) the text labels down out from under the scroll bar. Therefore, while I could manually position the top left text in interface builder to not be under the scroll bar, I can NOT manually position the bottom right next any further lower, and therefore can't use the bottom region of the screen at all.
Dr.Lightning is offline   Reply With Quote
Old 02-18-2010, 11:12 AM   #9 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 1
Default

I had this problem, and found a solution here:
http://www.iphonedevsdk.com/forum/ip...tml#post165423

Code:
- (void)viewWillAppear:(BOOL)animated {
	// to fix the controller showing under the status bar
	self.view.frame = [[UIScreen mainScreen] applicationFrame];
}
dotjay is offline   Reply With Quote
Old 02-19-2010, 02:45 PM   #10 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 13
Default

Quote:
Originally Posted by Sayid Cohen View Post
The following code solve it for me:

Code:
- (void)viewWillAppear:(BOOL)animated {
	// to fix the controller showing under the status bar
	self.view.frame = [[UIScreen mainScreen] applicationFrame];
}
==CONFIRMED== The above suggestion worked. In detail, in the context of the most simple Hello World example, which is in the context of the code I posted higher up, here's what I did. I found in MyViewController.m the function viewDidLoad, that was put there automagically by XCode when the class was created, but was commented out. I removed the comment-out to restore the code, then added the appropriate code inside:

Code:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	self.view.frame = [[UIScreen mainScreen] applicationFrame];
    [super viewDidLoad];
}
And that fixed the problem.

==WHAT THIS MEANS== in essence is that the tutorial falls short of being purely "correct" and should have included this or a similar fix. Perhaps ==MORE TO THE POINT==, XCode should have put that code in there, running not commented out.
Dr.Lightning is offline   Reply With Quote
Old 08-18-2010, 05:03 AM   #11 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 1
Default

Dr.Lightning, I completely agree with you.

I've lost some time finding this solution which Apple should have noted in the tutorial.
CoolWind is offline   Reply With Quote
Old 02-03-2011, 05:42 PM   #12 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 18
Default

I love you, Doctor. This has bugged me for the whole year I've been working on this device. I've hacked and hacked and gotten it looking right each project but I always felt dirty. I can't believe that at the start of your program you have to tell the main view to run at its OWN resolution.
CBGraham is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 157,860
Threads: 88,915
Posts: 379,298
Top Poster: BrianSlick (7,072)
Welcome to our newest member, Harizonalsri
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:54 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0