Xcode 4 Error: "the view outlet was not set" - iphone

I'm starting to program using Xcode/iOS
I've been reading some books and tutorial...
For my first application, I tried to do a "Hello World"
I did the program following every single step in the right way, but when I run the application, the program crash...
I read some posts to find the solution, but even when I check or do the steps that the posts suggest, I still have the same error. I tried to do another project, but the result is always the same.
This the capture of my screen

Try to set your "View reference outlet to files owner" by dragging the link
from "Views" to "File's Owner" in your nib. I think that's why you are getting
the crash:

Change the Class of File Owner to your ViewController,
Then set the View Outlet Again..!!
If it doesn't work, delete the view and drag a new one from Library. Set File Owner and View outlet again.

Related

This class is not key value coding-compliant swift

Yes, there are several posts about this problem, but none of these seem to answer my problem?
I created a custom view in a nib file and connected it to code, exactly like here:
Link
Only differences:
My class is named EditorSectionView not CustomView
My outlet's name is customView, not contentView
Apart from the code, i did the following, as described in the gist:
In Interface-Builder, click on "File's Owner" and make the File owner's custom class "EditorSectionView", NOT the View itself
Drag and Drop the top level view (the "Custom view" named item from Interface Builder) to the EditorSectionView via Assistance Editor to create an outlet named customView.
Whenever i start the app and click on the button that should use this custom view, it crashes with the error:
"This class is not key value coding-compliant for the key customView".
However, when i have a look at the connections inspector, in my nib file, there is no "!" like some other posts pointed out and all seems to be fine.
I am using the nib file like that to instantiate it:
form +++ Section(field.name) {
let header = HeaderFooterView<EditorSectionView>(.nibFile(name: "EditorSectionView", bundle: nil))
}
This should create a new form section in Eureka, as described here: https://github.com/xmartlabs/Eureka/blob/master/README.md (Search for "You can use a Custom View from a .xib file:" in the readme).
I have tried to solve this for an hour now, but i don't know what else to do. All connections are set (the outlet, the class for the UI), the code itself copied from a gist, etc.
What am i doing wrong here?
Thanks.
EDIT:
If i set the custom class in the identity inspector as well to EditorSectionView, not only the File's Owner custom class to EditorSectionView, it doesn'T crash any more with "not coding compliant for key XY" but it crashes with EXC_BAD_ACCESS on the line i am calling loadNibNamed().
I found here the answer, that i should not set a custom class for the top level view, which will result again in "not coding compliant". So either way it still doesn't work...
Its difficult to tell without seeing what your connections are in the Xcode inspector, but sometimes if you connect an outlet and then rename it in your code, that outlet is still connected with the old name and you get a key-value compliance issue
Places to look are in the "User defined attributes table of your identity/inspector..
And also check your connections inspector

NSViewController StoryBoard Opening Window Error

I'm working on a program with several view-controllers, all of which I open at various instances as sheets, by controlling dragging from a button on one viewcontroller to another viewcontroller, and by selecting "Sheet". This has always worked, until now when recently tried to add another viewcontroller and connect it similarly. When I click the button to open it though, it crashes and throws the error: (NSButton): missing setter or instance variable. When I use the new button to open an old viewcontroller, it works, but when I use an old button to open a new viewcontroller, it doesn't. Anyone seen this before?
Turns out I wasn't specifying which viewController the data needed to be sent to so I made an if statement saying, "If this view controller, then" and "else" etc. which ended up working.

iphone uitableview - linking problems?

I am trying to follow a tutorial about xml parsing http://www.edumobile.org/iphone/iphone-programming-tutorials/parsing-an-xml-file/ . The tutorial does not explain how to link and that is the part that i am stuck on. Looking at the source code provided i can see that "view" is linked with "file owner". In MY file, when i do this, i cannot link them. It does not highlight. Does anyone know why? what are the usual causes for this? (new to iphone). Thanks for any help!
You will find this helpful http://mobiforge.com/developing/story/iphone-programming-fundamentals-outlets-and-actions
This one is specific to XCode4 but is also helpful to understand the Interface Builder basics
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iPhone101/Articles/04_InspectingNib.html
If you add a new file (a subclass of view controller) you will get three files .h,.m and .xib. The File owner is always connected to the correct View Controller which happens to the owner of this nib(.xib) file. you can verify the same as shown in image below.
If this is the case then I am sure you can always link up your new elements (labels,buttons) to the correct Outlet. Just a reminder here that the declaration should start with the keyword IBOutlet so that It shows up in the interface builder.
eq IBOutlet UILabel *lblTitle;

'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the GameView nib but the view outlet was not set

This is not the same situation as the multitude of other similar questions here.
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the GameView nib but the view outlet was not set.'
You might be thinking "do as it says, connect the File's Owner to the View in IB!". But the thing is, I don't even HAVE a GameView.xib in my project or even in the project directory.
I do have a "GameViewController.m" and matching "GameViewController.xib" in my project. Using that GameViewController is what brings up this error, but I don't understand where it gets the idea to try and load "GameView.xib". Shouldn't it use "GameViewController.xib" instead?
If I grep my project directory, I do see it referenced from "UserInterfaceState.xcuserstate".
<string>file://localhost/Users/bemmu/Dropbox/b2/iphone/ValleyStory/ValleyStory/GameView.xib</string>
This mentioned file does not exist. I might have had a file with that name before and renamed/deleted it, but it's not being referenced to from anywhere that I can see in IB.
Did I manage to confuse xcode?
My solution was a little different.
Click on the xib in interface builder
Select File's Owner on the left
Open the File's Owner's connections inspector
If the view property isn't yet wired, control-drag it to the view icon (under the file's owner and first responder icons).
Check any nib files you're using (like MainWindow.xib). If you are loading GameViewController from a nib, check the file it's loading from (under the info tab in the inspector). Make sure it's set to "GameViewController" and not "GameView".
I had this issue as well, but had to solve it a different way. Basically, I have a view controller name MainViewController, which has a xib named MainViewController.xib. This nib has it's view property set to the File Owner which was MainViewController.
I also made a MainView.xib that contained a view that was going to be programmatically added to the view defined in MainViewController.xib and it's view. It basically encapsulated an internal view that would be in the MainViewController.xib's view, and also had it's File Owner set to MainViewController.
So basically, I wanted MainViewController.xib to load as the nib for the MainViewController object, and inside MainViewController, at some later point, I would add the internal view specified by MainView.xib.
A couple issues arose:
1.) I found in the Apple docs that when loading a view controller via storyboard or nib:
"If the view controller class name ends with the word “Controller”, as
in MyViewController, it looks for a nib file whose name matches the
class name without the word “Controller”, as in MyView.nib.
It looks for a nib file whose name matches the name of the view
controller class. For example, if the class name is MyViewController,
it looks for a MyViewController.nib file."
Therefore, you cannot have a nib called MainView.xib if you also have a nib called MainViewController and want MainViewController.xib to be the primary nib for MainViewController.
2.) Even if you delete MainView.xib or rename it to something else (MainInternalView.xib in this case), you MUST delete / clean your iOS simulator as the old nib file (MainView.xib) will still remain in the application. It doesn't overwrite the whole application package when you rebuild / rerun your application.
If you don't want to reset your content settings (perhaps you have some data you want to preserve), then right-click on your application in your iOS Simulator folder, Show Package Contents, find MainView.nib, and delete it. Xcode will NOT do this automatically for you when you rebuild, so we need to manually remove the old nib.
Overall, don't make nibs named MainViewController and MainView, i.e. nibs with the same prefix. Call MainView.xib something else, like MainInternalView.xib.
I recently solved this issue. Make sure you back up your project before following the steps given here (just in case). These steps solved my issue
Quit Xcode
Navigate to UserInterfaceState.xcuserstate located at .xcodeproj/project.xcworkspace/xcuserdata/<username>.xcuserdata and delete the file.
Reopen Xcode. Xcode will create a new UserInterfaceState.xcuserstate which will be clean.
In my case this error was produced by dumb mistake - I delete _view view
In my case, I was not using a xib at all. I needed remove the .m file from Build Phases > Compile Sources and added it back.
Given you referenced it previously it sounds like xcode hasn't ackowledged it no longer exists. From the Product menu select "Clean" and then "Build" hopefully this will get past the old reference for you.
Face the same Problem, had to change the view's name in code:
MyViewController *controller = [[MyViewController alloc] initWithNibName:#"WrongViewName" bundle:nil];
To
MyViewController *controller = [[MyViewController alloc] initWithNibName:#"RightViewName" bundle:nil];
I had multiple views, and by accident (I don't know how this happenned) but my background view didn't have a file owner, so for anyone else who has this problem in the future, make sure all your views have a file owner.
I was gettint the same error then check the classname from interface builder and see that I typed the view controller class name at the custom class attribute.
UIViewController searches for a nib with the same name as the controller when passed nil to initWithNibNamed:bundle: Check that the file name that you pass to the initializer is correct and exists!
For example:(e.g. [[CCVisitorsController alloc] initWithNibName:nil bundle:nil] then UIViewController tries to load nib with name CCVisitorsController as default.
If that file does not exist then the error you mentioned is thrown.
I had this problem because I was doing something bad in
(id) initWithCoder:(NSCoder *) coder
which the NIB loads.

Changes in Interface Builder are not showing in SImulator or Device

I have a view that I created using default buttons and background in Interface Builder. The app runs properly. I added .png background images to the view and to the buttons. Build the app and run it and the updates do not show.
I've also tried something simple like changing the text of the button or add another button and the changes are not propagating.
I've cleaned targets, manually deleted builds in Finder, and have shutdown the computer. What else am I missing?
I had the same experience. It turned out that I'd renamed my class and my xib file, but in another class I was creating the view with:
MyNewViewController *myNewViewController = [[MyNewViewController alloc]
initWithNibName:#"MyOLDViewController" bundle:nil];
An oversight, but the surprising part to me is that when this Nib file didn't exist in my project, it managed to build successfully using a (presumably cached?) old Nib file... and the application happily ran, though showing an out of date interface.
Correcting what was passed to initWithNibName immediately corrected the issue for me.
This might sounds easy - but are you sure you linked up the view to the view controller in Interface Builder? I've done it before where I just forget to link them
I also had the same experience. For me the fix was to reset all content on the simulator.