Question

I have a tableviewcontroller and on the respective rowclick of the tableviewcontroller i want to show the details of that respective rows detail content.

The row details view will have a fixed content as follows:

  1. Header
  2. Title below header
  3. Image related to title
  4. Here I want to show the respective views of the uitabbarcontroller tab button

In the above points the content from point 1-3 will cover half of page of viewcontroller which will be fixed & bottom half of the viewcontroller will have the 4th point i.e. views of the respective tabbarbuttons which will change according to the views created for respective tabs.

I am not able to find any solution for keeping the top half of the view fixed. And how to keep the views of the tabbar restricted to the bottom half of the screen.

I am doing this application without using storyboard .

Searched a lot but didn't got any solution.

Please provide some example code or tutorial if any.

Following is the image of what i exactly want as i have created same in android.

sorry need to blurr contents of image.

enter image description here

In the above image following are the things i want fixed:

  1. the blue bar at top is header which will stay fixed.
  2. the brownbar below the header and the whitish image below the header are also fixed.
  3. The four buttons below the image are the tabbar buttons which in IOS will appear at bottom of the screen.
  4. below the tabbar button is the view containing the content of the 1st tabbar button.

My question is i want the first 2 of above points be fixed and the viewcontroller containing the views for respective tabbarbuttons should be seen on the rest half of the screen with the 4 tabbar buttons.

So if i click on any of the tab buttons only its view which is occupied by bottom half of the screen will change & the top half will remain static(fixed).

Hope my explaination make clear some doubts about the question.

----EDITED SOLUTION based on what @Simon McLoughlin suggested, following is the code:

I have implemented a function in which i have written code for implementing my scenario.

-(void)loadShowDetailsTabBarController
{
    ConceptViewController *conceptViewController;
    CastViewController *castViewController;
    ShowDetailsFeedbackViewController *showDetailsFeedbackViewController;
    PromosViewController *promoViewController;

    UIImage *conceptBtn = [UIImage imageNamed:@"showdetailstabidle_btn_bg.png"];
    UIImage *conceptBtnSelected = [UIImage imageNamed:@"showdetailstabselected_btn_bg.png"];


    UIImage *castBtn = [UIImage imageNamed:@"showdetailstabidle_btn_bg.png"];
    UIImage *castBtnSelected = [UIImage imageNamed:@"showdetailstabselected_btn_bg.png"];

    UIImage *feedbackBtn = [UIImage imageNamed:@"showdetailstabidle_btn_bg.png"];
    UIImage *feedbackBtnSelected = [UIImage imageNamed:@"showdetailstabselected_btn_bg.png"];

    UIImage *promoBtn = [UIImage imageNamed:@"showdetailstabidle_btn_bg.png"];
    UIImage *promoBtnSelected = [UIImage imageNamed:@"showdetailstabselected_btn_bg.png"];

    conceptBtn = [conceptBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    conceptBtnSelected = [conceptBtnSelected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    castBtn = [castBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    castBtnSelected = [castBtnSelected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    feedbackBtn = [feedbackBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    feedbackBtnSelected = [feedbackBtnSelected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    promoBtn = [promoBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    promoBtnSelected = [promoBtnSelected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        conceptViewController = [[ConceptViewController alloc] initWithNibName:@"ConceptViewController_iPad" bundle:nil];

        castViewController = [[CastViewController alloc] initWithNibName:@"CastViewController_iPad" bundle:nil];

        showDetailsFeedbackViewController = [[ShowDetailsFeedbackViewController alloc] initWithNibName:@"ShowDetailsFeedbackViewController_iPad" bundle:nil];

        promoViewController = [[PromosViewController alloc] initWithNibName:@"PromosViewController_iPad" bundle:nil];
    }
    else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        conceptViewController = [[ConceptViewController alloc] initWithNibName:@"ConceptViewController" bundle:nil];

        castViewController = [[CastViewController alloc] initWithNibName:@"CastViewController" bundle:nil];

        showDetailsFeedbackViewController = [[ShowDetailsFeedbackViewController alloc] initWithNibName:@"ShowDetailsFeedbackViewController" bundle:nil];

        promoViewController = [[PromosViewController alloc] initWithNibName:@"PromosViewController" bundle:nil];

    }

    conceptViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"CONCEPT" image:conceptBtn selectedImage:conceptBtn];

    castViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"CAST" image:castBtn selectedImage:castBtnSelected];

    showDetailsFeedbackViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"FEEDBACK" image:feedbackBtn selectedImage:feedbackBtnSelected];

    promoViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"PROMO" image:promoBtn selectedImage:promoBtnSelected];/**/

    UITabBarController *showDetailstabVC = [[UITabBarController alloc] init];

    showDetailstabVC.viewControllers = [NSArray arrayWithObjects:conceptViewController,castViewController,showDetailsFeedbackViewController,promoViewController, nil];

    showDetailstabVC.view.frame = CGRectMake(0, 250, screenSize.width, screenSize.height-250);

    self.view.window.rootViewController = showDetailstabVC;

    [self.view addSubview:showDetailstabVC.view];
}

Please let me know if my code is correct?

I am able to view what i wanted.

But now the problem is when i click on the tabbar buttons i get the following error:

exc_bad_access (code=exc_i386_gpflt)

The error is not given in debug screen, The app stops at the following line in main.m :

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

Was it helpful?

Solution

Ok so it turns out what you are trying to achieve is a UIViewController split vertically. Top half being static and bottom half containing a UITabbarController that will display UIViewControllers that will only occupy the space between the UITabbar and the static view.

I thought this could be done with making the UITabbarController a child, but I could be wrong. I have had 3 child UIViewController's on a screen before by simply setting the frame. You've said above that that didn't work for you so I see 2 options left.

  1. You create all of the tabs content to be smaller. So for example say the top view is 100px in height. In the UIViewController's in the tabs, simply set the frame of the UITableView (or the view or whatever the content is) to start at 100px for its Y value. This is a fairly bad solution in my opinion however it would require the least effort to do.

  2. You create a "Master" UIViewController that has a static section at the top and a horizontally scrolling UIScrollView with paging enabled. And add the individual UIViewController's as child viewControllers to that. Not sure if you could create a Tabbar and listen for events and use that to programmtically scroll it, or if you would have to create your own UIView that looks like a Tabbar and put buttons on it to scroll left / right.

The second method is a fairly common thing to do. I've worked on a few apps that have done it and have seen many posts online about how to achieve it. Like so: How do I put viewController's into a UIScrollView . It Simply requires adding the child viewControllers at increasing X values and setting the scrollViews content size to the total. Turn on pagging, turn off vertical scrolling.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top