Issue with Uicollectionview for nib but didn't get a UICollectionView - ios

I am new for IOS development , and I try to use UIcollectionView to show the photo.
I create a xib file from New file -> iOS -> User Interface -> View , and add a Collection View like the following picture.
But I got the following error log when it crash.
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '-[UICollectionViewController loadView]
loaded the "AITLocalGridViewController" nib but didn't get a UICollectionView.'
And it seems didn't call viewDidLoad
I have search for some information , some information indicated that I dint not connect the collection view in xib file
But I don't understand what it mean.
Could some one help me and teach me what to do ?

Make sure that you have connected UIcollectionview IBOutlet with “collectionview “ that you declared in your program. And also you should make delegate&data source connection(For making this, click on th Uicollectionview in the xib. Select Connection Inspector. Where you can see delegate and datasource.By pressing ctrl button drag and connect it to File’s Owner.)

Just remove the view in Storyboard and use the UICollectionView as direct child.

Make sure UICollectionViewController's "view" outlet is set to a UICollectionView. Setting the "collectionView" to a UICollectionView is not enough for a UICollectionViewController.

At the risk of stating the obvious, also make sure that the UICollectionView is inside a UICollectionViewController. This can be overlooked when you do something like adding an embedded view into your project, where the default embedded view is the standard view controller.

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.

Illegal configuration. Connection "cell" cannot have a prototype object as its destination

I have 2 errors
"Illegal configuration. Connection "cell" cannot have a prototype object as
its destination"
Connections dont duplicate, cells are empty, without other controls in them. I try to clean project and rebuild it, but it didnt help me. How can I fix it? Thank you
Are you trying to link outlets of the cells (or elements of the cells) directly to the view controller? That would be a problem.
If you want your table view to always have the same content, you can change its content to "static cells" in the storyboard, and then you can link it like that.
If you want the table view cells to change dynamically, you cannot do it that way. You need to create a UITableViewCell subclass for your cells, and create the outlets there.
If this doesn't help at all, please explain your problem a bit better.
You probably have an outlet from something like your view controller that's connected to a prototype cell in a table view. An outlet is a to-one relationship. The cell is going to be instantiated many times, so this doesn't make sense, and is an error.
The problem might be that the outlet from the ViewController was not connected to the desired object at all, although it might be connected from the desired object to the ViewController.
for example: the IBAction outlet can be seen from the UIButton's connection inspector for "touch up inside" as linked to the ViewController's IBAction method, but the ViewController's connection inspector will not link the IBAction method to the UIButton.
Same error when I copied/pasted the admob banner view from the official sample into my tableViewCell and connected the IBOutlet from viewController. So, Tiago Lira's explanation worked for me and I created the custom cell class and added banner iboutlet there. Thus the compile time error got resolved. The above question should be accepted.
The only reason for this error is that you have copied a storyboard item- It might be whole view controller or any sub element like the view, button, and label etc. So now the problem is that they have linked each other and now you have to find what is it and delete it.
But if you have copied the whole view controller and you have checked
all possible links you could but still you getting error then this
trick is for you- Copy the main view of that view controller and
delete that VC then a make new VC and paste the copied view in that
VC, so your constraints are safe you just have to give top, bottom,
left and right constraints for the main view.
I found a solution. I delete and add new cell many times, and finally project build without errors

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.

Custom table view cell in storyboard

I have a pretty strange situation. I use storyboard in order to go with the times. And I have a view controller in which I have UIScrollView in which I have UITableView with with custom table view cells. So my question is: how to make a custom table view cell from storyboard inside scroll view, because before I used to make a separate nib with a Custom Cell in it. But now I get this error: 'The NIB data is invalid.' So please, suggest me any solution or idea how to solve my problem. Thank you in advance
I had the same problem. Turned out that I had checked "Use Autolayout" in the Interface Builder Document pane of the Storyboard file. This throws the "invalid NIB" error when running on iOS 5.

Exception when trying to load view on iPad: "loaded the nib but the view outlet was not set", how do I add that outlet?

I get this exception:
Objective-C exception thrown.
Name: NSInternalconsistencyException
Reason: - [UIViewController_loadViewFromNibNamed:bundle:] loaded the "TestRunnerViewController_iPad" nib but the view outlet was not set.
Sure enough, if I inspect the iPhone view I created first, I can see this:
But, in the one that crashes, an iPad view for the same controller that I added manually, this outlet does not exist, and I can't figure out how to add it. I've looked under File's Owner, same place where I found the outlet on the working view, but I can't figure out where to drag the "new referencing outlet" connector, it doesn't seem to link up with anything:
So, the question is simple. How do I add the required view outlet to my new view?
Note that I'm using MonoTouch/MonoDevelop, but since this is a question related to Xcode Interface Builder 4, I doubt that is relevant.
Have you set the class type for File's Owner?

Resources