Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve "Static table views are only valid when embedded in UITableViewController instances" when creating an app?

I am an Objective-C beginner and I am going through the tutorial to create an IOS app using Apple developer articles.

https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/SecondTutorial.html#//apple_ref/doc/uid/TP40011343-CH8-SW1

I have created an unwind segue and I have gotten stuck. I have gone through SO posts such as given below

  1. StoryBoard issue in Xcode 6.1
  2. Change a UIViewController to a UITableViewController inside a storyboard?
  3. Want to create a cool static UI but : "Static table views are only valid..."

I tried to modify the story board source to use "tableViewController" instead of "viewController", but the storyboard won't open.

I am sure that there is an easy solution, but I don't know enough Objective-C or IOS development to know what it is, or how to implement it.

I have my controller implementing UITableViewController and my view as UITableView. I have attached the screenshot below.

XCode Storyboard setup

and the error message:

Error message and description

My source for ToDoListTableViewController.h is given below:

 #import <UIKit/UIKit.h>

@interface ToDoListTableViewController : UITableViewController

- (IBAction)unwindToList:(UIStoryboardSegue *)segue;

@end

and the implementation

#import "ToDoListTableViewController.h"

@interface ToDoListTableViewController ()

@end

@implementation ToDoListTableViewController

 . . . Other methods 

- (IBAction)unwindToList:(UIStoryboardSegue *)segue {
}
@end
like image 529
Kartik Avatar asked Mar 06 '15 23:03

Kartik


1 Answers

Your picture is kind of small so it's a bit hard to tell what we're looking at. Plus your descriptions are a bit vague.

The deal is that in order to set up a table view as a static table view, it must be managed by a UITableViewController, not a regular UIViewController.

A UITableViewController is a special subclass of UIViewController. When you go to add a new scene to your storyboard, you go to the list of UI objects, find the UITableViewController, and drag one onto the storyboard.

An annoying thing about UITableViewController objects is that the ONLY thing they manage is a table view. You can't use them to set up labels, buttons, and other UI elements. Just a table view and nothing else.

You said:

'I tried to modify the story board source to use "tableViewController" instead of "viewController"...'

I have no idea what that means. What is a "story board source"? You don't "Modify the storyboard source", you drag a UITableViewController onto your storyboard.

Then you said "...but the storyboard won't open." I also don't know what that means. You're going to have to explain that.

Luckily, there is an easy solution to this.

What you want to do is to create a regular UIViewController to manage everything but the table view, and then put a "Container View" in that view controller and set up an "embed segue" that installs a UITableViewController inside that container view.

Here's how you do that:

Search in the list of UI elements on the right side for "container". Drag a container view onto your view controller where you want your table view to appear. Then drag a UITableViewController onto a blank space on your storyboard to create a new storyboard scene. Then control-drag from the container view in your first view controller onto the UITableViewController. This creates an embed segue, which causes the UITableViewController to be loaded as a child view controller with its view inside and sized to fit in the container view.

Now you can have a window that has both a table view managed by a UITableViewController AND other contents.

There are more details to setting this up that are beyond the scope of a SO post. I suggest you do some googling on container views and embed segues and try to find a tutorial on setting them up.

like image 145
Duncan C Avatar answered Oct 23 '22 08:10

Duncan C