I am just looking at setting up a simple viewController programatically, I have a ViewController.xib file that I have set the background color to RED in interface builder. I have also added the following to my AppDelegate.m
#implementation syntax_MapViewAppDelegate
#synthesize window;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
viewController = [[MapViewController alloc] init];
[window addSubview:[viewController view]];
[window makeKeyAndVisible];
return YES;
}
-(void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
When I run the code it does what I expect apart from the white bar at the bottom of the screen, can anyone give me any pointers in how to remove this? I have a feeling I might need to position the view within the window, but I am not sure how?
cheers Gary
Please set your view frame.
viewController.view.frame = CGRectMake(0.0,20.0,320.0,460.0);
Now the view cover your full screen with Red color.
You can also set it from interface builder as well.
Something like this might save your problem:
[[viewController view] setFrame:CGRectMake(0, 20, 320, 460)];
Set your view to resize dynamically using the autoresizingMask or set it's frame explicitly.
Related
I am using an iAd for sharing among views, but there are two strange issues which I have been browsing over the internet for solution without finding clue, therefore I post my question and code here for brain storming.
.h:
#interface AppDelegate : NSObject {
UIWindow *window;
ADBannerView *adBanner;
appViewController *viewControllerApp;
}
.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions {
adBanner = [[ADBannerView alloc] initWithFrame:CGRectZero];
adBanner.currentContentSizeIdentifier =ADBannerContentSizeIdentifierLandscape;
adBanner.delegate = self;
adBanner.backgroundColor = [UIColor whiteColor];
adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
//----------------------------------------------------------------------------------
[window addSubview:viewControllerApp.view];
[window makeKeyAndVisible];
return YES;
}
appViewController.m
-(void)viewWillAppear:(BOOL)animated
{
//#ifdef LITE_VERSION
[SharedAdBannerView setFrame:CGRectMake(0, 40, 0, 0)];
[self.view addSubview:SharedAdBannerView];
//#ifdef
}
somewhere in the appViewController.m:
{....
playGameView = [[PlayGameViewController alloc] initWithNibName:#"PlayGameViewController"
bundle:nil];
[self.view insertSubview:playGameView.view atIndex:10];
}
So, there are two questions:
1. when the App is running, the iAd isn't displayed on the right position (shall be
0,40,0,0) but it doesn't show up unless I changed the position to (0,180,0,0), but it
actually wasn't on the 0,180. it looks like on 0,40.
When I move to 2nd view (PlayGameView), then click on the iAd, the iAd shows a full
screen View, then I close the iAd, the screen of PlayGameView was gone! it was replaced by
the rootView!! how can I close the iAd with the PlayGameView stays?
I don't see problem at rootView when the iAd is clicked and closed.. anyone can help will be
highly highly appreciated!
BR
Georg
ok, now I have finally found the problem, I replaced this
[self presentModalViewController:playGameView animated:NO];
from
[self.view insertSubview:playGameView.view atIndex:10];
then it work perfectlly.
now there is only one remain issue: position of iAd banner view
I have a tabbar app with only 1 tab.
Here is my didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
OneDayViewController *oneDayView = [[OneDayViewController alloc] initWithNibName:#"OneDayView" bundle:nil];
tabBarController.viewControllers = [NSArray arrayWithObject:oneDayView];
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES; }
In any method in OneDayViewController, I have this code:
UIView *superView = [self.view superview];
Question is: what is superView now? UIView? UIViewController or ... I don't know (sorry about that)
P/S: I ask this because I want to remove OneDayView and add another view to tabbar.
Thanks you very much.
Your superview will be tabBarController.view...
(Earlier i have told it is window I was wrong...)
post the code that showing/pushing OneDayViewController... so we can get clear idea about the superview...
I'm wanting to have my app (on launch) load a view that I have created over the top of the original view, then when a button is clicked the top view will disappear and show the main view underneath. I know this is terribly simple, but how would I do this? Maybe push the view in viewDidLoad?
Use a navigation controller
MyViewController *myView = [[MyViewController alloc] init];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:myView];
My2ndView *secondView = ....
[navControl pushViewController:secondView animated:NO];
[window addSubView:navControl.view]
This can be incredibly simple. When the user clicks the button, just do this
secondViewController.view.hidden = YES;
Just add the two views in your delegate, and do that in your delegate.
If you prefer, just do it "in" secondViewController! self.view.hidden = YES;
It sounds like you're just doing something simple ...... no need to bother with a view controller.
You ask how to display the second view, just like this ..
-(BOOL)application:(UIApplication *)applic`ation
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[window addSubview:yourMainView.view];
[window addSubview:theTemporaryView.view]; // it goes on top
[window makeKeyAndVisible];
application.idleTimerDisabled = YES;
return YES;
}
-(BOOL)eliminateTempView // example, when the user clicks on the button
{
theTemporaryView.view.hidden = YES;
[theTemporaryView release];
}
Hope it helps!
I am just looking at setting a up a custom UIViewController programatically (see code below) and I am just curious about the white line I am getting at the bottom of the display, I don't see this when I create the view using a NIB in InterfaceBuilder. Is it just a case of offsetting the frame down by the height of the status bar or am I missing something else?
EDIT:
Found it:
viewController.view.frame = CGRectMake(0.0,20.0,320.0,460.0);
CODE
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MyController *tempController = [[MyController alloc] init];
[self setMyController:tempController];
[window addSubview:[myController view]];
[window makeKeyAndVisible];
return YES;
}
SCREEN
Much appreciated ...
Gary
You could try setting up the frame of your controller's view to see what happens:
tempController.view.frame = CGRectMake(0, 0, 320, 480);
By the way, you have a probable memory leak in your method (that should be catched by clang if you enable it).
i guess this problem is related to bounds or Applicationframe. set everywhere bounds -'[[UIScreen mainScreen]bounds];' let's see ...
I'm using addSubView twice in my app and both times it adds the view too high up the view, its off the screen at the top. See below... I have load the views like this as I nothing else works, cause me problems.
I just don't understand why they are showing off the screen?
What do I need to do to fix this ?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:rootController.view];
[window makeKeyAndVisible];
lvc = [[GettingStartedViewController alloc]
initWithNibName:#"GettingStartedView" bundle:nil];
[window addSubview:lvc.view];
return YES;
}
And in my GettingStartedView ...
- (IBAction) showHelp:(id)inSender {
theController = [[HelpViewController alloc] initWithNibName:#"HelpView"
bundle:nil onPage:HelpPageGettingStarted];
[self.view addSubview:theController.view];
}
Set the location:
rootController.view.frame = CGRectMake(0, 20, 320, 460);
Check the wantsFullScreenLayout property of your root view controller, make sure it's not set.