Zhen
Zhen

Reputation: 12431

Objective C: Part of UITableView hidden by Tab bar controller

Hi I have a Uitableview added to a Uiviewcontroller as seen in the code below. The controller is part of a UITabbarcontroller.

The problem here is that the tab bar (at bottom of screen) overlaps with the table view. Is there any way to shorten the table height so that it is not partially hidden by the tab bar?

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame] autorelease];

    self.feedTableView = [[UITableView alloc]init];

    self.feedTableView.frame = self.view.bounds;

    self.feedTableView.delegate = self;
    self.feedTableView.dataSource = self;

    [self.view addSubview: self.feedTableView];

    [self getData];

    [self.feedTableView reloadData];
}

Upvotes: 1

Views: 2290

Answers (1)

vakio
vakio

Reputation: 3177

You have two problems here:

  • You set self.view in viewDidLoad (it should already have been set in loadView).
  • You set the view frame to applicationframe, but your view does not take up the whole applicationframe (the tab bar controller's view probably does that).

When you have a tabbarcontroller and set viewcontrollers inside it, the tabbarcontroller sets up all the viewcontrollers (tells them when to load and what size to have and when to show). You should never need to set the view's frames in this case. So removing that first line after [super viewDidLoad]; should fix your problem.

Upvotes: 3

Related Questions