24

I'm creating a view like:

enter image description here

For this I'm trying to use a Storyboard in which I add 2 TableViews (both as 'Static Cells') and then I manually add my Cell content directly from the storyboard...

In my storyboard it looks great but when I build I get:

en.lproj/MainStoryboard.storyboard: error: Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances

How can I fix this error?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Cehm
  • 1,502
  • 1
  • 12
  • 14
  • 21
    the image is gone. this is not useful. why not integrating images by uploading them directly to stackoverflow? – brainray Jun 29 '12 at 08:38
  • 1
    this one has a good answer in it: http://stackoverflow.com/questions/22364230/static-table-view-outside-uitableviewcontroller – Sruit A.Suk Mar 07 '16 at 17:23

4 Answers4

34

I've also ran into an issue when changing an existing custom view controller, making it extends UITableViewController. XCode isn't smart enough and won't realize it already fits its requirements.

You can solve this problem by editing storyboard source code and changing <viewController ... to <tableViewController....

Original source: https://plus.google.com/108665969482300807329/posts/J4mCASMA3pZ

juanignaciosl
  • 3,435
  • 2
  • 28
  • 28
  • 1
    And don't forget to change the closing `` XML tag so there is no mismatch! – Jeff Sep 13 '13 at 23:10
  • 4
    I tried this with Xcode 5.1, but it no longer works. I got the following error: "The document "MainStoriboard.storyboard" could not be opened. Could not verify document content." Now changing it to dynamic, it seems to be the only way now. – Homam May 23 '14 at 11:17
  • seems like bad practice – Todd Hopkinson Dec 16 '14 at 22:33
  • With Xcode 6, you need to delete `view` on storyboard first, otherwise, you can't open storyboard with Interface Builder. – Allen Jan 10 '15 at 09:04
  • This still applies in Xcode 7.. 3 years later. Thanks for this! That being said, @Radu's answer below seems less hacky. – Bilal Akil May 03 '16 at 13:17
  • 1
    Still applies in xcode 9...This isn't a hack though if you have just accidentally dropped a normal controller onto the storyboard made some additions and then realised you have dropped a table view controller and can't be bothered starting over – Joe Maher Sep 25 '17 at 03:20
22

Add a UITableViewController to your view. It should hold a UITableView. Define this as a static table view, and make it grouped. Add two sections. One with one row, and the other with two rows. Add your Labels buttons and sliders to the rows again.

I do not know why you would want to have two UITableViews here?

Øystein
  • 1,163
  • 1
  • 12
  • 23
  • Well, It seems it's the only way to obtain this "style" without having to create custom stuffs isn't it ? – Cehm Feb 14 '12 at 13:22
  • Probably. I do not know how apple has implemented the static table feature in the storyboard, but since you get an error message when you try to define it outside a UITableViewController, it surely indicates that they have code behind it that supports this kind of behavior. I recommend using a controller to handle the UITableView anyway because you get lots of stuff free that way. – Øystein Feb 14 '12 at 13:26
  • Great !!I just did what you said and this worked pretty well. – Cehm Feb 14 '12 at 13:45
  • 15
    Addition note: Changing the view controller's class to UITableViewController **won't** work(same as custom class inherent it). **Only** Dragging a new UIViewController to story would work. – johnlinvc May 07 '12 at 09:12
4

The only way to make this work in Xcode 6, and the way Apple intended this to work is to embed a TableViewController in a container view, if you must. It seems that you cannot hack your way through as described by juanignaciosl, in Xcode 6.

So the steps would be as follows:

  1. Create a table view controller
  2. replace the table view in this controller with the table from your "problematic" view controller, with all its static cells and so on

If your table view is part of a more complex ui and it is not the main view of your view controller then continue as below

  1. create a containerView in your "problematic" view controller, in the same position as your now-moved static table view. This will also create automatically another viewcontroller and a seque - delete those.
  2. left click drag or ctrl drag from the container view to the tableviewcontroller which contains your static table and choose embed

This is not as nice as before, because your tableview is stripped away in a separate view controller in interface builder and this might have an impact on your existing code and outlets. But for big static tables it is the better alternative to generating all the content dynamically.

Radu Simionescu
  • 4,518
  • 1
  • 35
  • 34
2

You can make it dynamic and then switch of scrolling:

[yourTableName setScrollEnabled:NO];
Ash Var
  • 241
  • 2
  • 3
  • 12