0

I have a subclass of UITableViewController.

I overrid initWithCoder so that when the controller initializes it adds five items to the UITableView that it creates by default (I did not create a UITableView in IB because the UITableViewController creates one).

I would like to add a header (with 2 buttons) that I created in Interface Builder to that tableview.

I linked an IBOutlet to the header from Interface Builder and I set it to be the header of the UITableView created at initialization.

The problem is that although I did this I only see the UITableView with the 5 items (displayed corectly) but I don't see the header. It's like it ignores the header from the Storyboard or something like that.

Any idea why?

Thanks.

Alex Craciun
  • 473
  • 1
  • 3
  • 13
  • just drag and drop UIView to header part...means above prototype cells – Bhavin Bhadani Sep 14 '15 at 12:27
  • possible duplicate of [Table Header Views in StoryBoards](http://stackoverflow.com/questions/7841167/table-header-views-in-storyboards) – Bhavin Bhadani Sep 14 '15 at 12:30
  • Do you want the headers to be inside the tableview or outside? Inside the tableview will make it NOT visible if u scroll down, out the tableview will make it stay. – Saheb Roy Sep 14 '15 at 12:38
  • Inside the tableview. But if I override `initWithCoder` to add a few items when it creates the `UITableView` by default, it no longer displays the header from Interface Builder. – Alex Craciun Sep 14 '15 at 12:51

2 Answers2

0

I just captured one GIF from of my example StoryBoard that you can drag UIView on top of your UItableViewController and make it resize as par your need. pelase check following.

enter image description here

Hope that help to you. After drag view on UITableview you just need to create IBOutlet and make your task complete :D

Community
  • 1
  • 1
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • Thank you. It did help. However if I understood corectly the `UITableViewController` automatically creates a tableview when it's initialized right? So could I just not add a `UITableView` in IB? – Alex Craciun Sep 14 '15 at 12:46
  • yes if you are used UIViewController then you need to Create IB for UITableview. But you are using UITableviewcontroller so no need to create IB for UITableview – Nitin Gohel Sep 14 '15 at 12:49
  • I overrid `initWithCoder` to add a few items to the tableview and now it seems that the `UITableViewController` is just ignoring the storyboard file because the tableview (created by default) appears but the header (from IB) does not appear. Any idea why? – Alex Craciun Sep 14 '15 at 12:53
  • you need to used UITableview delegats for maintain table Cell, check apple doc about all delegate. By using this you can maintain all things https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/ – Nitin Gohel Sep 14 '15 at 12:58
  • I've set the datasource protocol and implemented the methods. The tableview created by default works fine except for the header which is made in IB. I've updated the question. – Alex Craciun Sep 14 '15 at 13:11
  • for new query you need to ask new question instead of update. if the original question solve then you must accept the answer and start new question with new query. – Nitin Gohel Sep 14 '15 at 13:13
  • One last question. What method gets called when the `UITableViewController` gets initialized. I mean where would it be best to add some items to the data source? In the initializer for the `UITableViewController` or in `viewDidLoad`? – Alex Craciun Sep 14 '15 at 13:55
  • view did load is the first called so you need to create array for tableview at viewdidLoad – Nitin Gohel Sep 15 '15 at 08:55
0

Drag a uiwebview into right above the tableview's first cell.

Jason Nam
  • 2,011
  • 2
  • 13
  • 22