iOS App with multiple view controllers - ios

My current application on appDelegate loads a main.xib screen which only contains an two images background and logo. This screen behind code determines if the user is logged on the system if not it will show the login else it will show the dashboard.
The application has been created as a single view application, sample code of the appDelegate:
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
self.Main = [[vcMain alloc] initWithNibName:#"vcMain" bundle:nil];
self.window.rootViewController = self.Main;
[self.window makeKeyAndVisible];
}
else
{
self.MainiPad = [[vcMain_iPad alloc] initWithNibName:#"vcMain_iPad" bundle:nil];
self.window.rootViewController = self.MainiPad;
[self.window makeKeyAndVisible];
}
On the Main.m I have the following on the viewDidLoad:
if (islogged)
{
vcDashboard *vcDash = [[vcDashboard alloc] initWithNibName:#"vcDashboard" bundle:nil];
_ncMain = [[UINavigationController alloc] initWithRootViewController:vcDash];
_ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque;
_ncMain.view.frame = self.view.bounds;
[self.view addSubview:_ncMain.view];
ViewActive = vDash;
}
else
{
vcLogin *login = [[vcLogin alloc] initWithNibName:#"vcLogin" bundle:nil];
login.modalPresentationStyle = UIModalPresentationFormSheet;
login.view.frame = self.view.bounds;
[self presentViewController:login animated:YES completion:nil];
}
There is a menu button available on the Dashboard that presents the user with a series of options to select another screen and when pressed it will activate the following method:
- (void)displayView:(NSString *)strView Notification:(NSNotification *)notification{
if(_ncMain)
{
[_ncMain.view removeFromSuperview];
_ncMain = nil;
}
if ([strView isEqual: #"Dashboard"])
{
vcDashboard *vcDash = [[vcDashboard alloc] initWithNibName:#"vcDashboard" bundle:nil];
_ncMain = [[UINavigationController alloc] initWithRootViewController:vcDash];
_ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque;
_ncMain.view.frame = self.view.bounds;
[self.view addSubview:_ncMain.view];
ViewActive = vDash;
}
else if ([strView isEqual: #"Catalog"])
{
vcCatalog *vcCat = [[vcCatalog alloc] initWithNibName:#"vcCatalog" bundle:nil];
_ncMain = [[UINavigationController alloc] initWithRootViewController:vcCat];
_ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque;
_ncMain.view.frame = self.view.bounds;
[self.view addSubview:_ncMain.view];
ViewActive = vCatalog;
}
else if ([strView isEqual: #"News"])
{
vcNews *vcNew = [[vcNews alloc] initWithNibName:#"vcNews" bundle:nil];
_ncMain = [[UINavigationController alloc] initWithRootViewController:vcNew];
_ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque;
_ncMain.view.frame = self.view.bounds;
[self.view addSubview:_ncMain.view];
ViewActive = vNews;
}
}
My doubt here is I don't seem to know if this is the correct way of changing between screens when an option is selected from this menu and if is right to always addSubview to the principal screen. Don't know if using the navigationcontroller template is a solution. I'm concern of the memory consumed by the app when doing all of this, also I'm currently using ARC on the project.

I recommend you that avoid the addSubview method if possible. UiNAvigationController offer you a good way to handle different viewControllers. If you make addSubview the changeRotation event, for example, is not called. And when you make a pop the viewController is dealloced.
Good luck!

Related

UINavigationBar with UISegmentedControl partially covers childViews

I have read many other threads on this and the Apple docs, but haven't found a solution yet for my particular problem.
My app uses a UITabBarController as the rootViewController, and in one of the tabs I have a UISegmentedControl in the navigationBar to switch between three child UITableViewControllers.
(In the real app two of the childVCs are a custom UIViewController, I'm just using three UITableViewControllers for the sample app).
The segmentedControl setup and the switching all works fine. The thing that goes wrong is that only the first UITableViewController is shown correctly. For the second and third one, part of the first cell is hidden under the navigationBar. When I click through all three, the first one is still ok.
I have made a little sample app to show what's going on, using very bright colors for demonstration purposes: https://www.dropbox.com/s/7pfutvn5jba6rva/SegmentedControlVC.zip?dl=0
Here is also some code (I'm not using storyboards):
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
FirstViewController *fvc = [[FirstViewController alloc] init];
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController: fvc];
SecondViewController *svc = [[SecondViewController alloc] init];
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController: svc];
// Initialize tab bar controller, add tabs controllers
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = #[firstNavigationController, secondNavigationController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
// FirstViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.title = #"One";
self.view.backgroundColor = [UIColor orangeColor];
UITableViewController *vc1 = [[UITableViewController alloc] init];
UITableViewController *vc2 = [[UITableViewController alloc] init];
UITableViewController *vc3 = [[UITableViewController alloc] init];
vc1.view.backgroundColor = [UIColor redColor];
vc2.view.backgroundColor = [UIColor blueColor];
vc3.view.backgroundColor = [UIColor greenColor];
self.viewControllers = #[vc1, vc2, vc3];
self.segmentTitles = #[#"Red", #"Blue", #"Green"];
self.segmentedControl = [[UISegmentedControl alloc] initWithItems: self.segmentTitles];
[self.segmentedControl addTarget: self
action: #selector(segmentClicked:)
forControlEvents: UIControlEventValueChanged];
self.navigationItem.titleView = self.segmentedControl;
self.segmentedControl.selectedSegmentIndex = 0;
// set the first child vc:
UIViewController *vc = self.viewControllers[0];
[self addChildViewController: vc];
vc.view.frame = self.view.bounds;
[self.view addSubview: vc.view];
self.currentVC = vc;
}
- (void)segmentClicked:(id)sender
{
if (sender == self.segmentedControl)
{
NSUInteger index = self.segmentedControl.selectedSegmentIndex;
[self loadViewController: self.viewControllers[index]];
}
}
- (void)loadViewController:(UIViewController *)vc
{
[self addChildViewController: vc];
[self transitionFromViewController: self.currentVC
toViewController: vc
duration: 1.0
options: UIViewAnimationOptionTransitionFlipFromBottom
animations: ^{
[self.currentVC.view removeFromSuperview];
vc.view.frame = self.view.bounds;
[self.view addSubview: vc.view];
} completion: ^(BOOL finished) {
[vc didMoveToParentViewController: self];
[self.currentVC removeFromParentViewController];
self.currentVC = vc;
}
];
}
So obviously my question is, why does this happen, and what can I do to fix it?
Edit: adding screenshots.
EDIT: Based on the answer below I changed the code in the animation block to:
[self.currentVC.view removeFromSuperview];
if ([vc.view isKindOfClass: [UIScrollView class]])
{
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, self.bottomLayoutGuide.length, 0);
[UIView performWithoutAnimation: ^{
vc.view.frame = self.view.bounds;
((UIScrollView *)vc.view).contentInset = edgeInsets;
((UIScrollView *)vc.view).scrollIndicatorInsets = edgeInsets;
}];
}
else
{
vc.view.frame = self.view.bounds;
}
[self.view addSubview: vc.view];
Now it works. I'm going to try this with a custom UIViewController as well.
The issue is that you do not set the correct content inset to each table view. The system attempts to do it for you, but I guess your setup is too complex for it, and it only does it for the first tableview that is loaded in viewDidLoad. In your loadViewController: method, when replacing the currently displayed view, make sure to set both the contentInset and scrollIndicatorInsets to the values of the previous view. I think the system will manage to set the correct insets later, in case you rotate to landscape. Try it. If it doesn't, you will need to do it on your own in viewDidLayoutSubviews.

Button to Present ViewController After Tutorial (which Loads For 1st Time Only)

I have a tutorial ViewController called tutorialViewController which only presents itself for the first time the app is launched. This is how I do that:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL hasRunBefore = [defaults boolForKey:#"FirstRun"];
if (!hasRunBefore) {
[defaults setBool:YES forKey:#"FirstRun"];
self.window.rootViewController = [tutorialViewController new];
self.window.backgroundColor = [UIColor whiteColor];
// RESideMenu Stuff that Must Be Done
leftSideMenuViewController *leftMenuViewController = [[leftSideMenuViewController alloc] init];
rightSideMenuViewController *rightMenuViewController = [[rightSideMenuViewController alloc] init];
musicPlayerViewController *navigationController = [[homeViewController alloc] init];
RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:navigationController
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
sideMenuViewController.menuPreferredStatusBarStyle = 1;
sideMenuViewController.delegate = self;
sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
sideMenuViewController.contentViewShadowOpacity = 0.6;
sideMenuViewController.contentViewShadowRadius = 12;
sideMenuViewController.contentViewShadowEnabled = YES;
self.window.backgroundColor = [UIColor blackColor];
}
else
{
NSLog (#"Not the first time this controller has been loaded");
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[homeViewController alloc] init]];
// RESideMenu Stuff that Must Be Done
leftSideMenuViewController *leftMenuViewController = [[leftSideMenuViewController alloc] init];
rightSideMenuViewController *rightMenuViewController = [[rightSideMenuViewController alloc] init];
RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:navigationController
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
sideMenuViewController.menuPreferredStatusBarStyle = 1;
sideMenuViewController.delegate = self;
sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
sideMenuViewController.contentViewShadowOpacity = 0.6;
sideMenuViewController.contentViewShadowRadius = 12;
sideMenuViewController.contentViewShadowEnabled = YES;
self.window.rootViewController = sideMenuViewController;
self.window.backgroundColor = [UIColor blackColor];
}
This works well so far - if I load the app for the first time, it shows tutorialViewController. If I close it and open it again, it shows homeViewController.
I'd just like to know how to add an IBAction to take me from tutorialViewController to homeViewController. Currently, I wrote this:
- (IBAction)goToHomeViewController:(id)sender {
homeViewController *navigationController = [homeViewController new];
[self presentViewController:navigationController animated:YES completion:^{
}];
NSLog(#"Start button pressed");
}
It presents homeViewController but it does not show the navigation bar, etc. - as it would if homeViewController was the rootViewController.
Here are some more details
tutorialViewController does not show a status bar or a navigation bar. It is simply a scrollview that takes up the whole screen.
'homeViewControllerhas a navigation bar with a left bar button and right bar button that brings up otherviewControllers`.
I've searched other SO questions but they are mostly to do with Storyboards, which I am not using. Just .xibs (and .h and .m).
How do I present homeViewController from tutorialViewController just as it would display if homeViewController was the rootViewController?
Wrap homeViewController in a UINavigationController should work.
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:homeViewController] animated:YES: completion:nil]
You can also do like this.
In your 'if' condition add tutorialViewController as
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[tutorialViewController alloc] init]];
And in the goToHomeViewController function add,
homeViewController *navigationController = [homeViewController new];
[self.navigation pushViewController:navigationController animated:NO];
So first time the tutorialViewController act as rootview controller and if you want to hide NavigationBar add following code,
[[self navigationController] setNavigationBarHidden:YES animated:YES];

Trouble pushing view controller from a welcome screen [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a welcome screen that only shows the first time the user opens the app. The screen is working great, but I can't get it to show the normal screen when the user clicks done.
Here is the code in the app delegate to create the normal screen -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
if([[NSUserDefaults standardUserDefaults] boolForKey:#"TermsAccepted"]!=YES)
{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:#"TermsAccepted"];
}
// Override point for customization after application launch.
FeedViewController *feedViewController = [[FeedViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:feedViewController];
[self.window addSubview:nav.view];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
self.tabBarController = [[UITabBarController alloc] init];
[[UITabBar appearance] setTintColor:[UIColor redColor]];
// FeedViewController
feedViewController=[[FeedViewController alloc] init];
feedViewController.tabBarItem.image=[UIImage imageNamed:#"Describe-Home_Icon_NormalArtboard-1"];
feedViewController.title = #"Timeline";
feedViewController.tabBarItem.title = nil;
//TodayViewController
TodayViewController *todayViewController = [[TodayViewController alloc] init];
todayViewController.tabBarItem.image = [UIImage imageNamed:#"Today_Icon"];
todayViewController.title = #"Today";
todayViewController.tabBarItem.title = nil;
//CreateViewController
self.createViewController = [[CreateViewController alloc] init];
self.createViewController.tabBarItem.image = [UIImage imageNamed:#"Create_Icon"];
self.createViewController.title = #"Create";
self.createViewController.tabBarItem.title = nil;
//AlertViewController
AlertsViewController *alertsViewController = [[AlertsViewController alloc] init];
alertsViewController.tabBarItem.image=[UIImage imageNamed:#"Alerts_IconArtboard-1"];
alertsViewController.title=#"Alerts";
alertsViewController.tabBarItem.title = nil;
//ProfileViewController
ProfileViewController *profileViewController = [[ProfileViewController alloc] init];
profileViewController.tabBarItem.image=[UIImage imageNamed:#"Profile_IconArtboard-1"];
profileViewController.title=#"Profile";
profileViewController.tabBarItem.title = nil;
NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:2];
self.tabBarController = [[UITabBarController alloc] init];
UINavigationController *feedNavigationController = [[UINavigationController alloc] initWithRootViewController:feedViewController];
[tabBarViewControllers addObject:feedNavigationController];
feedNavigationController = nil;
UINavigationController *todayNavigationController = [[UINavigationController alloc] initWithRootViewController:todayViewController];
[tabBarViewControllers addObject:todayNavigationController];
todayNavigationController = nil;
UINavigationController *createNavigationController = [[UINavigationController alloc] initWithRootViewController:self.createViewController];
[tabBarViewControllers addObject:createNavigationController];
createNavigationController = nil;
UINavigationController *alertsNavigationController = [[UINavigationController alloc] initWithRootViewController:alertsViewController];
[tabBarViewControllers addObject:alertsNavigationController];
alertsNavigationController = nil;
UINavigationController *profileNavigationController = [[UINavigationController alloc] initWithRootViewController:profileViewController];
[tabBarViewControllers addObject:profileNavigationController];
profileNavigationController = nil;
self.tabBarController.viewControllers = tabBarViewControllers;
tabBarViewControllers = nil;
[self.window addSubview:self.tabBarController.view];
return YES;
}
In feedViewController to push the welcome view controller -
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"TermsAccepted"]){
NSLog(#"Second time opening the app");
}
else{
WelcomeViewController *welcomeViewController = [[WelcomeViewController alloc] init];
[self.navigationController pushViewController:welcomeViewController animated:NO];
}
To go back to feed that isn't working -
-(void)showDone:(UIButton *)sender {
if (self.navigationItem.rightBarButtonItem.tintColor == [UIColor redColor]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"TermsAccepted"];
FeedViewController *feedViewController = [[FeedViewController alloc] init];
[[UIApplication sharedApplication] keyWindow].rootViewController = feedViewController;
self.tabBarController.tabBar.hidden = NO;
self.navigationController.navigationBar.hidden = NO;
}
}
It looks like when you show your Welcome screen, you push it onto a UINavigatonController. But when you click Done, you're trying to set the root view controller on the window instead of just popping the view controller from the navigation controller. It also looks like you're creating a new instance of your FeedViewController instead of using the instance you already have created.
Also, have you checked to see if it's even executing the code in your showDone: method? You're using == to compare the tintColor of a UIBarButtonItem with a UIColor, but using == will only return true if they're both the exact same UIColor instance, which they might not be. You'll want to use the method isEqual: to compare two colors, so you would do the following instead:
[self.navigationItem.rightBarButtonItem.tintColor isEqual:[UIColor redColor]]
Note that this won't always return YES for equal colors if they're in different color spaces, but most of the time this should work.
Also, you should consider moving your code out of your app delegate, because generally application:didFinishLaunchingWithOptions: is used only for things that need to be done immediately upon startup. It shouldn't be used to initialize a bunch of view controllers, those should only be initialized when it's time for them to be displayed.

Unable to call Lock Screen view controller from AppDelegate

I have implemented the KKLockscreen view controller and is working well within the in-app settings controller. Able to set passcode and change them as well.
I am having problem to call he lock screen view from appdelegate. I have added delegate .h file and imported the view controller in .m file. still it's not calling the lockscreen. any help?
below is my code.
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if ([[KKPasscodeLock sharedLock] isPasscodeRequired]) {
KKPasscodeViewController *vc = [[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil];
vc.mode = KKPasscodeModeEnter;
vc.delegate = self;
dispatch_async(dispatch_get_main_queue(),^ {
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.navigationBar.barStyle = UIBarStyleBlack;
nav.navigationBar.opaque = NO;
} else {
nav.navigationBar.tintColor = _navigationController.navigationBar.tintColor;
nav.navigationBar.translucent = _navigationController.navigationBar.translucent;
nav.navigationBar.opaque = _navigationController.navigationBar.opaque;
nav.navigationBar.barStyle = _navigationController.navigationBar.barStyle;
}
[_navigationController presentModalViewController:nav animated:NO];
});
}
}
i have checked it with my code and it is working ,ya but you have not give nib name here in this line and i have given may be that why it is not displaying your view.
KKPasscodeViewController *vc = [[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil]
-(void)applicationDidBecomeActive:(UIApplication *)application {
RootViewController *vc = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
dispatch_async(dispatch_get_main_queue(),^ {
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.navigationBar.barStyle = UIBarStyleBlack;
nav.navigationBar.opaque = NO;
} else {
nav.navigationBar.tintColor = navigationController.navigationBar.tintColor;
nav.navigationBar.translucent = navigationController.navigationBar.translucent;
nav.navigationBar.opaque = navigationController.navigationBar.opaque;
nav.navigationBar.barStyle = navigationController.navigationBar.barStyle;
}
[navigationController presentModalViewController:nav animated:NO];
});
}

Orientation Problem while using insertSubview

I get an orientation problem while using the following to code to display a view on top of a split view.
[window addSubview:aSplitViewController.view];
[window insertSubview:aViewController.view aboveSubview:aSplitViewController.view];
the plain view has a couple of buttons and labels.
So the problem I am facing is that the first view opens in landscape mode but the labels and buttons on the view are in portrait mode.
UPDATE: Here is some code so if anyone wants to see more details...
In my App Delegate
- (void) makeSplitViewController {
NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
// First tabbbar item
// detail view
detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
UINavigationController *navDetailView = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
navDetailView.hidesBottomBarWhenPushed = YES;
// root view
rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
rootViewController.detailViewController = detailViewController;
rootViewController.navigationItem.title = #"List";
UINavigationController *navRootView = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
navRootView.hidesBottomBarWhenPushed = YES;
navRootView.navigationBar.barStyle = UIBarStyleBlackTranslucent;
splitViewController = [[UISplitViewController alloc] init];
splitViewController.tabBarItem.title = #"Face Sheet";
splitViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
splitViewController.navigationItem.title = #"Face Sheet";
splitViewController.viewControllers = [NSArray arrayWithObjects:navRootView, navDetailView, nil];
splitViewController.delegate = detailViewController;
splitViewController.hidesBottomBarWhenPushed = YES;
[controllers addObject:splitViewController];
// Second tabbbar item
scoreViewController = [[ScoreCardViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
scoreViewController.tabBarItem.title = #"Score Card";
scoreViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
scoreViewController.navigationItem.title = #"Score Card";
[controllers addObject:scoreViewController];
tabBarController.viewControllers = controllers;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Create tabbar
tabBarController = [[UITabBarController alloc] init];
//tabBarController.delegate = self;
// Set window
[window addSubview:splashController.view];
[window insertSubview:tabBarController.view belowSubview:splashController.view];
[self.window makeKeyAndVisible];
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
return YES;
}
and here is the code in my SplashScreenView
- (IBAction) proceedButtonClick:(id)sender
{
// Initialize loginpopview
PhysicianLoginViewController *loginViewController = [[PhysicianLoginViewController alloc] init];
popOverController = [[UIPopoverController alloc] initWithContentViewController:loginViewController];
popOverController.popoverContentSize = CGSizeMake(350, 200);
popOverController.delegate = self;
// Set a notification to dismiss it later
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(loginViewControllerDone:) name:#"loginViewControllerDone" object:popOverController.contentViewController];
// Present popover
if ([popOverController isPopoverVisible])
{
[popOverController dismissPopoverAnimated:YES];
}
else
{
[popOverController presentPopoverFromRect:CGRectMake(485, 600, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
// Dismiss popview controller and setup the tabbar
- (void)loginViewControllerDone:(NSNotification *)notification{
[[NSNotificationCenter defaultCenter] removeObserver:self];
// Button in content view controller was tapped, dismiss popover...
[self.popOverController dismissPopoverAnimated:YES];
// remove subview
[self.view removeFromSuperview];
// set tabbar
i3EAppDelegate *appDelegate = (i3EAppDelegate *) [[UIApplication sharedApplication]delegate];
[appDelegate makeSplitViewController];
}
It would be great if someone could point out where I am going wrong. I have been stuck with this problem for quite a few days and I have tried everything that comes to my mind...
UIWindow has a subview that it uses for rotations and puts other views inside of that. You need to insert yourself into the root view (or something lower), not the window. Look at -[UIWindow rootViewController].
UIView *rootView = [[[self window] rootViewController] view];
[rootView addSubview:view];
This will work as long as you're using something with a root view controller. This will work as long as rootViewController isn't nil. If you're doing a raw "View Based" application, then it's usually best to pick another view and add your view as its sibling rather than digging through the undocumented hierarchy:
UIView *sibling = ... (some other view)
[[sibling superview] addSubview:view];

Resources