UITableViewController inside a UIViewController with swift and Xcode 8 - ios

I have a problem similar to this:
UITableViewController inside a UIViewController
I follow exactly the same steps.
I have a UIViewController with my custom class: MyCustomClassViewController and UITableViewController named MyCustomUITableViewController.
Inside of my ViewController I added a Container View and drag and drop to my UITableView and selected embed.
Ok, now, when I executed the project, I got this error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'containerView is
required.'

Your view controller classes are incorrectly constructed. Look at your embed segue, and make sure that:
The source view controller is marked in the identity inspector as MyCustomClassViewController
The destination view controller is marked in the identity inspector as MyCustomUITableViewController
Also go back to your code and make sure also that you have the correct inheritance:
MyCustomClassViewController should be a UIViewController subclass
MyCustomUITableViewController should a UITableViewController subclass
You might even have to delete the segue, and even the view controllers, from the storyboard, and recreate them along with the container view and the embed segue.

Related

How do I avoid using the [UITableViewController loadView] when trying to present a UIViewController (and not a UITableViewController)

I am making an iPad app that, among other things contain a view in which to set options.
This "Options" View has two container-views, each holding a TableView with two different kinds of options in them, and switches to turn these options on or off.
The problem is that when I try to make a button from my main ViewController that will open the options view, I get the following error:
Screenshot of signal SIGABRT error
with this in the output:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-c2d-Su-6Id" from storyboard "Options", but didn't get a UITableView.'
I don't know why the underlying function [UITableViewController loadView] is used, as I do not expect my Options-view to be a TableView - the tables are in container views.
I am using different storyboards, and a segue to a storyboard reference to present the Options View modally. I have tried deleting both the button, the segue and the Storyboard reference, replacing them with new ones, and renaming my ViewController.swift file, and all the references to it, with no luck
I have also tried looking for other solutions here on the site, but I have had no luck, and I begin to fear it might be because of the tableViews in the containerViews...
I am quite new to learning swift and Xcode, so please keep your explanations simple to follow, and assume that I am completely incompetent :-)
I'm guessing you probably added a Container View, which automatically places a "child" view controller onto the Storyboard, and then simply changed the Class of that child VC to UITableViewController --- which, as you found out, doesn't work.
To use a table view controller as the child, add your Container View, then add a normal UITableViewController to the Storyboard. Then, Ctrl-Drag from the Container View to the new table view controller and select Embed from the popup menu.

Inheriting from uitableviewcontroller crashes app

I dragged a view controller into my app then created a new view and made it segue to that view. I created a class for that view and made it inherit from uitableviewcontroller but when I segue to that view the app crashes terminating with uncaught exception of type nsexception. Is this because the view is not a table view controller? Or am I missing something else? Thanks.
I bet it crashes because the tableViewController expects its root view to be a tableview and you embedded the tableview in another view

nib but didn't get a UITableView using PFQueryTableViewController

I am trying to add a search feature to my app but the screen needs to have a navigation bar in addition the search bar on the UITableView. I am getting the following error when i perform the segue (click a button) and the view loads
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "2Gx-ec-tTH-view-HBf-bD-79u" nib but didn't get a UITableView.'
Here is what it looks like on my storyboard.
I believe the problem is that this scene is managed by a class called "AllDataViewController" and it manages the UIView and is a subclass of UITableView it is actually PFQueryTableViewController
//AllDataTableViewController.h
#interface AllDataTableViewController : PFQueryTableViewController <UISearchDisplayDelegate, UISearchBarDelegate, UITableViewDelegate>
So I am not sure what I am doing wrong here. But let me know if you have any suggestions or if I need to add any more information.
Because your view controller subclasses UITableViewController (well, indirectly via PFQueryTableViewController), it expects its view property to refer to an instance of a UITableView. If you look at the object hierarchy in the storyboard scene I think you will find that the root of the scene is not a UITableView, but a UIView.
How did you add the navigation bar? The correct method is to select "embed in..." from the Editor menu in Image Builder.

Subclassing a UITableViewController without nib or storyboard?

I'm trying to subclass UITableViewController just with just code without a nib or storyboard. Upon loading its view I get this error:
'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "BYZ-38-tfr-view-1bC-Xs-vdC" nib but didn't get a UITableView.'
I've tried setting self.tableView with a new table view in :loadView but that doesn't fix it, nor does setting it in any initializers. Any solutions?
Edit: The class is a plain subclass of UITableViewController generated from the "new file" menu. No customizations have been made.
It may help to note that the project itself has a storyboard, and I'm loading the UITableViewController subclass by making the app's starting view controller to be the subclass.
The error is easily reproducible by creating a new single-view template project in Xcode, generating a plain UITableViewController subclass, and setting the only view controller in the storyboard to be of the UITableViewController subclass type.
Edit 2: Problem solved, check comments.
I fixed it by avoiding any storyboard whatsoever. Originally I had it being loaded via the projects main storyboard. Instead, I now load up the subclass instance in a separate view controller, avoiding the error.

how to include the leah PullRefreshTableviewController in a UIViewController?

I have to include the leah pulltorefresh table view in an existing ios project. (https://github.com/leah/PullToRefresh)
The existing table view is defined in a xib file and it's linked to an outlet in the controller class (a subclass of UIViewController).
My first try was to make the controller inherit of PullToRefreshTableViewController (from leah's project) and add the refresh fonction in that same controller. But it doesn't work, I have this error :
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "CampaignViewController" nib but didn't get a UITableView.'
Since PullToRefreshTableViewController is a subclass of UITableViewController, I think I can't make my controller inherit from it (am I right?). How can I do this? Thanks
Try creating TableViewController from scratch, making it a subclass of PullToRefreshTableViewController.
It's much simpler than creating a table view in IB, connecting outlets, and then filling all necessary delegate and datasource methods.

Resources