How do I make my iOS7 UITableViewController NOT appear under the top status bar?

前端 未结 13 1952
旧巷少年郎
旧巷少年郎 2020-12-13 14:04

My root controller is a TabBarController (tabbed application). One of the tabs, is a UITableViewController. When I switch to that and scroll through the items, they show up

相关标签:
13条回答
  • 2020-12-13 14:34

    For me an easy solution was (code is in C# that's because appears to be invalid)...

    1. Just in the UITableViewController constructor create a new UIView (set same dimension of the TableView).

    2. Add the TableView to the new created view.

    3. Set new created View to the UITableViewController's View property...

    On the constructor of the UITableViewController

    var view = new UIView ();
    view.Frame = this.TableView.Frame;
    view.AddSubview (this.TableView);
    
    this.View = view;
    
    0 讨论(0)
  • 2020-12-13 14:38

    Have you tried adding something like this to the view controller's viewWillAppear method:

     if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
     {
        self.edgesForExtendedLayout = UIRectEdgeNone;
     }
    
    0 讨论(0)
  • 2020-12-13 14:40

    suppose your table's @IBOutlet is

     @IBOutlet var tableView: UITableView!
    

    create a function prepareTable(). add the below line into that method

    tableView.contentInset.top = UIApplication.shared.statusBarFrame.height
    

    call this method from ViewDidLoad()

    0 讨论(0)
  • 2020-12-13 14:42

    I added the following to viewWillAppear

    self.tableView.contentInset = UIEdgeInsetsMake(22, 0, 0, 0);
    
    0 讨论(0)
  • 2020-12-13 14:43

    In case anyone misses the How the story ended section at the end of the (now long) question, the short answer is: Use a simple UIViewController with a TableView, instead of a TableViewController if you want to achieve the stated goal.

    0 讨论(0)
  • 2020-12-13 14:44

    You can also solve this through Storyboard.

    Select the Table View from the Project Outline (left side of the editor) and then go to Properties (right side) > Size inspector tab > Scroll View > Content Insets > Top

    0 讨论(0)
提交回复
热议问题