I have two UITabBarControllers in my mainwnidow.nib wired to my appdelegate.
In my app delegate, I can load either one:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//either
[window addSubview:tabBarController.view];
//or
[window addSubview:tabBar2Controller.view];
[window makeKeyAndVisible];
}
and autorotation works.
If I add both (with the expectation to swap between them later):
[window addSubview:tabBarController.view];
[window addSubview:tabBar2Controller.view];
then autorotation stops working...everything is always portrait.
Thanks in advance for any tips...
Hmmm, I don't like this design. Typically windows should only have one subview.
Add another view controller that holds the instances of your tabBarControllers, and do the switching from there. That will fix your problem.
After thinking it through more, I realized I could just switch out the tabBarController.viewcontrollers array.
In IB I added both sets of tabs to a single tabbar, and then the appdelegate seperates them into two arrays and swaps between them as needed.
It works fine, but the jury is still out on whether the UI is effective
Related
I have added the 5 UINavigationController in my main Window. Like this
[self.window addSubview:navgContForBuzzyRequest.view];
[self.window addSubview:navgContForMyBuzzies.view];
[self.window addSubview:navgContForNewBuzzies.view];
[self.window addSubview:navgContForSetting.view];
[self.window addSubview:navigationController.view];
when i comment above 4 addSubView my Application perform normal Orientation but as soon as i uncomment a single UINavigationController above [self.window addSubview:navigationController.view]; my Orientation for the last addSubview is block.
As far as i have notice the View which i have addSubview first only give response to Orientation delegate
can anyone guide me what i am making wrong
ok i got you problem this happens becuase you are adding navigationController as a subView in window so that first view is set to default rootViewController so that orientation delegate methods of first is calls only.
try this
self.window.rootViewController=navgContForBuzzyRequest;
self.window.rootViewController=navgContForMyBuzzies;
self.window.rootViewController=navgContForNewBuzzies;
self.window.rootViewController=navgContForSetting;
self.window.rootViewController=navigationController;
Hihi all,
This could very well be a silly question. I would like to navigate to my "Login View" upon the launching of my application. My current tries:
In my first UIViewController's viewDidAppear method, perform a [self presentModalViewController:LoginView animated:YES], this works, but the screen shows my main UIView first, then slide my LoginView from bottom to top. I can't find a way to perform it without the animation.
In my first UIViewController's viewDidAppear method, perform a [self.view addSubview:LoginView.view], it ends up with exc_bad_access error.
Basically, my requirement is to perform certain checks upon starting of the application, if a login is required, the application shall display the LoginView, otherwise, it should stay as my main UIView.
Please advice what is the best way of achieving this, instead of the above two silly methods. Thanks in advance!
:)
How about trying it in **- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {**
example :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
LoginViewController *aLoginViewController = [[LoginViewController alloc] init];
[self.navigationController presentModalViewController:aLoginViewController animated:NO];
[aLoginViewController release];
return YES;
}
your 1st step is a good way..
but to stop animation, its very simple. Set animated to NO.
[self presentModalViewController:aLoginViewController animated:NO];
once ur done with ur validation, just dismiss this aLoginViewController.
Instead of -viewDidAppear, it sounds like you want to use -viewWillAppear:, which will allow you to present your login controller before the initial view is displayed.
-presentModalViewController:animated is the right method to display your login controller's view.
The view is created in interface builder, and is strangely cutting off at the bottom, and help or suggestions, is appreciated.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
Edit: I don't actually have a nib for the view controller, but instead a main window nib and a nib for two different views which are different themes.
Also if I use:
self.window.rootViewController = self.viewController;
it does not happen, but sadly this will crash in iOS 3.2 or below.
I experience the same problem, what I do is translating view 20 pixels down in ViewDidLoad then everything works fine. The problem surely is related to the statur bar but I do not know a solution other than this workaround.
To translate the view use this:
self.view.transform = CGAffineTransformMakeTranslation( 0, 20 );
In interface builder you need to check the dimensions of the view. You will see that it is too short (your height is probably set to 440, but it should be 460, or 480 if you don't have the status bar). This is probably why it appears to be cutting off.
Try enabling a simulated status bar in IB.
I'm relatively new to iOS programming. I have made a few basic apps before, and I'm getting back into it once again.
A problem I had a while back, and now is coming to haunt me is this.
When I create a new UIViewController subclass, myViewController (with xib) and add this code to get the add the view to the window, the contents always appear too high up, by the same width as the default/recommended left/right margin.
The code to add the view to the window is this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:[NSBundle mainBundle]];
[self setMyViewController:aViewController];
[aViewController release];
UIView *controllersView = [myViewController view];
[window addSubview:controllersView];
[window makeKeyAndVisible];
return YES;
}
For example, if I change the background colour of the view, I get a white strip at the bottom of the page when running in the simulator.
Any ideas?
Thanks
I don't think the problem is in that code. Although I guess you've done this already, it is probably a good idea to double check the .xib file. It may have an offset set in its position properties.
Also, it may be caused by the status bar not being set correctly. If you want to hide it, you can add an entry (UIStatusBarHidden -> true) in the info.plist file to set it to be hidden.
Either way check the dimensions of the .xib are the expected ones. And bear in mind the size of the status bar; the dimensions of the .xib file are different depending on whether the status bar is shown or not.
In an application I'm developing, everything starts from a navigation controller, which then loads up several pages.
My question is, how can I load up a new view ABOVE this? The closest I've got is to do this in the App Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self checkAndCreateDatabase];
[self readDataFromDatabase];
[window addSubview:[navigationController view]];
// Add this
[window addSubview:[newViewController view]];
[window makeKeyAndVisible];
return YES;
}
However this will load the view half way across the screen with no way of having it start at (0,0). Do anyone have a better suggestion?
Thanks
You can show regular views on top of everything by showing it as a modal view. Here is a sample project. http://dl.dropbox.com/u/3656129/ModalViewExample.zip