Can not push viewcontroller again in IOS - ios

I have 3 ViewController, flow: rootviewcontroller is view1 , when i click on "Start"button in view1, it push view2 and then click on "Status" button in view2, it push view3 . In view3 has uitabbarcontroller and inside tabbarcontroller has 2 UINavigationController . My problem is : When click on "Logout"button in UINavigationController in tabbarcontroller, i call back view2. But when view2 appear, I click on "Status"button, it can not push view3.
Code for created UItabbarcontroller
self.tab=[[UITabBarController alloc]init];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
{
// code for 4-inch screen
// LoginButton.frame = CGRectMake(0, 518, 80, 49);
self.tab.view.frame = CGRectMake(0,0,320,568);
}
else if (screenBounds.size.height == 1024)
{
//code for ipad
}
else if (screenBounds.size.height == 480)
{
// code for 3.5-inch screen
// LoginButton.frame = CGRectMake(0, 430, 80, 49);
self.tab.view.frame = CGRectMake(0,0,320,480);
}
// FirstViewController
UploadTab *uploadview=[[UploadTab alloc]initWithNibName:nil bundle:nil];
UINavigationController *uploadTabItem = [[[UINavigationController alloc] initWithRootViewController: uploadview] autorelease];
uploadview.title=#"Uploading";
uploadview.tabBarItem.image=[UIImage imageNamed:#"Uploading.png"];
self.title = #"FirstViewControllerTitle";
//SecondViewController
ConvertTab *convertView=[[ConvertTab alloc]initWithNibName:nil bundle:nil];
UINavigationController *convertTabItem = [[[UINavigationController alloc] initWithRootViewController: convertView] autorelease];
convertView.title=#"Convert";
convertView.tabBarItem.image=[UIImage imageNamed:#"Convert.png"];
//ThirdViewController
CompletedTab *completedView=[[CompletedTab alloc]initWithNibName:nil bundle:nil];
UINavigationController *completedTabItem = [[[UINavigationController alloc] initWithRootViewController: completedView] autorelease];
completedView.title=#"Completed";
completedView.tabBarItem.image=[UIImage imageNamed:#"Completed.png"];
UIBarButtonItem * LogoutItem= [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"Logout.png"] style:UIBarButtonItemStylePlain target:self action:#selector(logout)];
self.navigationItem.rightBarButtonItem = LogoutItem;
self.tab.viewControllers=[NSArray arrayWithObjects:uploadTabItem,convertTabItem, completedTabItem, nil];
[self.view insertSubview:self.tab.view belowSubview: uploadview.view];
[self presentModalViewController:self.tab animated:NO];
I use below code to call back view2:
- (void) handleBack:(id)sender
{
ChooseViewController *chooseview = [[ChooseViewController alloc] init];
[self.navigationController pushViewController:chooseview animated:NO];
[chooseview release];
}
I used [self.navigationController presentModalViewController:loginView animated:YES];
. I thinks it made view2 can not push view3.
Do you have any suggestions ? Thanks a lot

Hope this might be useful:
NSArray *viewControllers = [[self navigationController] viewControllers];
for (int i = 0; i < [viewContrlls count]; i++){
id obj = [viewControllers objectAtIndex:i];
if ([obj isKindOfClass:[yourViewControllername class]]){
[[self navigationController] popToViewController:obj animated:YES];
return;
}
}
using this you can come back to any specific view.

Related

Present view controller before initial view controller is shown

I have an app that has the following structure:
The main view controller is a tab bar view controller that has 4 tabs.
Users can only access these view controllers when they are logged in. When app launches, it loads it's initial view controller (the tab bar one), and then I check to see if user is authenticated. If it's not, I present a login view controller.
The problem I'm having is that when app launches, it's loading the tab bar controller and from that controller it presents the login view controller, but it does so with a small time window that shows the tab bar controller's view on the screen, before the login's view. I need to directly present the login view, from the tab bar controller, but without showing tab bar controller's view in that small time interval, as it's not user friendly.
I read some answers on stackoverflow about presenting the new view controller without animation, and that's what I'm doing, but the problem persists.
I hope I've been clear enough on the issue, if you need more information just let me know.
EDIT: I'm presenting the login view controller on applicationDidBecomeActive: on applicationDelegate.m
In app delegate, In didFinishLaunchingWithOptions,
In condition if login or not,
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:#"your identifier"];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
You should something like this when you have view controller in storyboard.
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
FirstViewController *firstviewController = [storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
SecondViewController *secondviewController = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
firstviewController.tabBarItem.image = [UIImage imageNamed:#"24-around-7"];
firstviewController.tabBarItem.title = #"First";
secondviewController.tabBarItem.title = #"Second";
secondviewController.tabBarItem.image = [UIImage imageNamed:#"60-around-7"];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
tabBarController.viewControllers = #[firstviewController,secondviewController];
self.window.rootViewController = tabBarController;
And in FirstViewController's viewDidAppear you should check for user logged in or not and present view controller.
BOOL loginStatus = [[NSUserDefaults standardUserDefaults] boolForKey:#"isLoggedIn"];
if(loginStatus == NO){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LoginViewController *loginViewcontroller = [storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self presentViewController:loginViewcontroller animated:YES completion:nil];
}
After successful login just dismiss login view controller . If user logout just present the loginviewcontroller
CREATE NEW .H .M
(this is my code)
yourController.h and yourController.m
then open
yourcontroller.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSLog(#"initWithFrame");
[self setupPinPopUp];
}
return self;
}
-(void)setupPinPopUp{
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = CGRectMake(0, 66, kSCREEN_WIDTH, kSCREEN_HEIGHT-66);
blurEffectView.userInteractionEnabled = TRUE;
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleSingleTap:)];
[blurEffectView addGestureRecognizer:singleFingerTap];
blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:blurEffectView];
UIView *popUpMainView = [[UIView alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH/2-150, kSCREEN_HEIGHT/2-160, 300, 270)];
popUpMainView.backgroundColor = Clear;
[self addSubview:popUpMainView];
UIView *popUpInsideView = [[UIView alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH/2-150, kSCREEN_HEIGHT/2-102, 300, 210)];
popUpInsideView.backgroundColor = White;
popUpInsideView.layer.cornerRadius = 2.0;
popUpInsideView.clipsToBounds = TRUE;
[self addSubview:popUpInsideView];
UIImageView *imgCircleView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 0, 100, 100)];
imgCircleView.layer.cornerRadius = 50;
imgCircleView.backgroundColor = White;
imgCircleView.clipsToBounds = TRUE;
[popUpMainView addSubview:imgCircleView];
UIImageView *imgInnerCircleView = [[UIImageView alloc]initWithFrame:CGRectMake(25, 8, 50, 50)];
imgInnerCircleView.backgroundColor = Clear;
imgInnerCircleView.image = [UIImage imageNamed:#"support"];
[imgCircleView addSubview:imgInnerCircleView];
UILabel *lblHeading = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, popUpMainView.frame.size.width, 45)];
lblHeading.text = #"CUSTOMER SUPPORT";
lblHeading.numberOfLines = 0;
lblHeading.textColor = Black;
lblHeading.textAlignment = NSTextAlignmentCenter;
lblHeading.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:21];
[popUpInsideView addSubview:lblHeading];
UIButton *btnPhoneNumber = [[UIButton alloc]initWithFrame:CGRectMake(0, lblHeading.frame.size.height+lblHeading.frame.origin.y+10, popUpMainView.frame.size.width, 45)];
[btnPhoneNumber setTitle:#"18002345678" forState:UIControlStateNormal];
[btnPhoneNumber setTitleColor:Black forState:UIControlStateNormal];
btnPhoneNumber.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
btnPhoneNumber.titleLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:18];
[btnPhoneNumber addTarget:self action:#selector(callSupport:) forControlEvents:UIControlEventTouchUpInside];
[popUpInsideView addSubview:btnPhoneNumber];
UIButton *btnEmail = [[UIButton alloc]initWithFrame:CGRectMake(0, btnPhoneNumber.frame.size.height+btnPhoneNumber.frame.origin.y+10, popUpMainView.frame.size.width, 45)];
[btnEmail setTitle:#"support#vurify.com" forState:UIControlStateNormal];
[btnEmail setTitleColor:Black forState:UIControlStateNormal];
btnEmail.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
btnEmail.titleLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:18];
[btnEmail addTarget:self action:#selector(emailSupport:) forControlEvents:UIControlEventTouchUpInside];
[popUpInsideView addSubview:btnEmail];
}
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
[self removeFromSuperview];
}
-(IBAction)callSupport:(id)sender{
NSString *phoneNumber = [#"tel://" stringByAppendingString:#"180023456789"];
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber] options:#{} completionHandler:^(BOOL success)
{
if (success) {
NSLog(#"Opened url");
}
}];
}
-(IBAction)emailSupport:(id)sender{
[self removeFromSuperview];
}
//call the method like this wherever you want to call
//IN APP DELEGATE
UIView *rectView;
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[rectView removeFromSuperview];
rectView = [[VurifyAppValidation alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT)];
[self.window addSubview:rectView];
}

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.

Greedy UITabBarController?

I'm making a custom UIViewController which holds to sub view controllers. They are put inside the main view controller this way:
- (void) setHeaderViewController:(UIViewController *)vc
{
[self setViewController:vc isHeader:YES];
_headerViewController = vc;
}
- (void) setDetailViewController:(UIViewController *)vc
{
[self setViewController:vc isHeader:NO];
_detailViewController = vc;
}
- (void) setViewController:(UIViewController*) viewController isHeader:(BOOL)isHeader
{
UIViewController* viewControllerRef = ((isHeader) ? _headerViewController : _detailViewController);
if(viewControllerRef == viewController)
return;
const CGSize selfSize = self.view.frame.size;
CGRect viewFrame;
if (isHeader)
{
viewFrame = CGRectMake(0, 0, selfSize.width, 150);
}
else
{
viewFrame = CGRectMake(0, 150, selfSize.width, selfSize.height-150);
}
UIView* viewControllerView = viewController.view;
[viewControllerView setFrame:viewFrame];
[viewControllerView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | ((isHeader) ? UIViewAutoresizingFlexibleBottomMargin : UIViewAutoresizingFlexibleTopMargin))];
[self.view addSubview:viewControllerView];
}
If I put two UIViewControllers inside of each sub view controller slot, the sizes defined in the method is respected. However, when putting a UITabBarController, it gets greedy and occupies the whole space:
UIViewController *vc = [[WIFCustomerDetailHeaderViewController alloc] initWithNibName:#"WIFCustomerDetailHeaderViewController" bundle:nil];
[self setHeaderViewController:vc];
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = #"Personal Data";
vc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Personal Data" image:nil tag:0];
vc1.view.backgroundColor = [UIColor redColor];
vc1.view.frame = CGRectMake(0,400,100,100);
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = #"Diagnosis";
vc2.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Diagnosis" image:nil tag:0];
vc2.view.backgroundColor = [UIColor purpleColor];
vc2.view.frame = CGRectMake(0,500,50,50);
NSArray *tabs = [[NSArray alloc] initWithObjects:vc1, vc2, nil];
WIFCustomerDetailTabViewController *tvc = [[WIFCustomerDetailTabViewController alloc] init];
[tvc setViewControllers:tabs];
[self setDetailViewController:tvc];
Does anyone knows what can be happening here? I can't find the cause...
Images below..
Documentation for the UITabBarController class says, "you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller".
It seems that you're attempting a design that's specifically not supported.

iPad UIPopover presented over UIBarButtomItem covers BarButtomItem?

I have UIBarButtomItem that shows popover when pressed:
//add help button
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Help", #"Help") style:UIBarButtonItemStylePlain target:self action:#selector(showInfoBubble:)] autorelease];
infoBubblePopOverVisible = NO;
self.infoBubblePopOverController = nil;
Here is show info bubble:
- (void) showInfoBubble: (id) sender {
[self dismissPopoverControllerExplicitly];
if (self.infoBubblePopOverController == nil) {
InfoBubbleViewController *controller = [[InfoBubbleViewController alloc] initWithNibName:#"InfoBubbleViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
self.infoBubblePopOverController = [[UIPopoverController alloc] initWithContentViewController:navigationController];
[controller release];
[navigationController release];
}
//present popOverController
[self.infoBubblePopOverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
infoBubblePopOverVisible = YES;
}
But when presented popover is presented partially covering barbuttomitem:
How can i fix this?

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