Search code examples
iosuitableviewuitabbar

UITabbar and UITableView


Hi I'm writing a iOS app with a UITableView and UITabBar. as below,

enter image description here

I'm adding the tab bar programatically and it sits on a part of my UITableView. So I can't see the last couple of table cells.

How can I fix this?

Thank you.


Solution

  • You have to change the frame of your tableView. In portrait orientation you should decrease it's height, in landscape mode you should deal with it's width.

    This code is just a sample, it wasn't tested and may need minor improvements, but it shows an idea:

    -(void) viewDidLayoutSubviews
    {
        if(UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
        {
            CGRect r = self.tableView.frame;
            r.size.height-=49;
            self.tableView.frame = r;
        }else
        {
            CGRect r = self.tableView.frame;
            r.origin.x += 49;
            r.size.width-=49;
            self.tableView.frame = r;
        }
    }