Made a change in Interface Builder, Xcode is not showing it - objective-c

So here is what my interface looks like at the moment:
Here is what I have changed it to in Interface Builder:
This is what is shown after I run it in Xcode:
Obviously the two programs are not communicating - if someone could point me in the right direction it would be great.
Thanks heaps!

If stuff isn't in sync, try cleaning your build. Product>Clean should do the trick.

The programs communicate through the NIB/XIB files. Make sure you have saved your changes from Interface Builder before rebuilding in XCode (this does not happen automatically). Also double check that the file Interface Builder is editing is the exact same file (not a copy) of the one in your XCode project.
Hope this helps.

This happens if you rename a nib but forget to change name of nib name passed in to a ViewController in its initWithNibName: bundle initialiser.
For example. If I have a nib named ViewOne.xib which I'm passing in to a ViewController like this:
ExampleViewController *exampleViewController = [[ExampleViewController alloc] initWithNibName:#"ViewOne" bundle:nil];
And I change the name of the nib to ViewTwo, Xcode isn't smart enough to amend this reference in the initialiser, so now a xib that noi longer exists is being passed in to the ViewController. For reasons that I cannot fathom, despite the fact there is no longer a nib called ViewOne.xib, Xcode maintains some sort of ghost of the file and you won't get an error because of the missing nib. Cleaning and deleting derived data did not get rid of this ghost reference, at least in my case.
The fix is easy - just amend the nib name in the initialiser to your new name:
ExampleViewController *exampleViewController = [[ExampleViewController alloc] initWithNibName:#"ViewTwo" bundle:nil];

Related

How to rename a UIViewController and its xib [duplicate]

This question already has an answer here:
Changing xib name [duplicate]
(1 answer)
Closed 8 years ago.
I am using iOS 5 and Xcode 4.2. In my project i have a UIViewController with xib. Now i want to give seperate name for UIViewController and xib.
Is it Possible?
After changing the name of UIViewController the controllers showing warning and i can not connect connect controllers to this class.
Within your header file (SomeViewController.h), highlight the class name and from Xcode menu > Edit > Refactor > Rename
And follow the on screen instructions.
Good Luck.
Renaming a class file names and interface files are possible. However, renaming class name by refactor option on Xcode is appreciated than doing it manually.
For refactoring GOTO: "symbol navigator(next to project navigator)">>
right click on your file name >> "REFACTOR">> RENAME.
Having different names for classes and interface do not bring up issues, however its the standard to keep the interface file name same as that of the corresponding class files.
You just change the .h and .m file names by click on those files. What ever new name you gave to those files use that name while importing those files other than that don't change those name any where. try it once..
After changing the name of UIViewController the controllers showing
warning and i can not connect connect controllers to this class.
Find the code where you're instantiating the view controller. It should look something like:
MyViewController *mvc = [[MyViewController alloc] initWithNibName:... bundle:...];
When you find that line, look at the values you're passing for the nib name and bundle. Chances are, you'll need to change the nib name that you're passing in. Either you're passing an incorrect name, or you're passing nil. If if the first case, simply correct the name. If you're passing nil, again, just change that to reflect the actual name of the .xib file. (It's common to use nil because UIViewController will use the class name as the nib name if you pass in nil, so nil is a handy shortcut.)

Unknown Class <XXX> in Interface Builder file

Hi initially I had an application where the app delegate defined the initial view controller to be an .xib of some other class. I deleted this class, its header and its .xib because I wanted the initial view controller to be of another class.
In the app delegate class I deleted the original reference from the class I did not want and typed
self.window.rootViewController = [[NewClass alloc] initWithNibName:#"NewView" bundle:nil];
This works like a charm as the initial view is now "NewView". However the console gives me an error of the title above. I did a search on the whole project of the deleted class and there are no references to it. Furthermore I even deleted the actual files. Also, I deleted the simulator's cache.
Thanks in advance.
Well the error says that there is an unknown class in IB. So look through all of your xib/storyboards. I am almost certain a view, controller, etc... (whatever your subclass was of), is declared using that class.
Searching all of your files or code for that class will not help since it is an Interface Builder error, so check around there.

Error loading .xib - application crash

I am banging my head against a brick wall. I am trying to push a view onto a UINavigationController in the usual manner:
[[self navigationController]pushViewController:vc animated:YES];
When I do this the app crashes with the following error:
__CFStringEncodeByteStream + 17
Thread 1: EXC_BAD_ACCESS (code=2,address=xxxxx)
Now, I have replaced the ViewController in question with a template provided by XCode and I do not get the error so the issue must be with my UIViewController class. Furthermore, if I replace the nib name with that of the template UIViewController class it works .i.e.
MyViewController *myVc = [[MyViewController alloc]initWithNibName:#"XCodeViewController" bundle:nil];
This leads me to think that the issue is actually with the nib and not the class itself. I have checked through all the connections and there are no errors or warnings.
Hopefully somebody can help.
Thanks
I was dealing with a very frustrating bug similar to yours, and everything was in place.
The newly created xib was added to the Bundle resources, no nil pointers or released pointer, NSZombieEnabled was set. The File's Owner was set to the correct ViewController as well
After sitting down with my senior for 30 minutes, we finally realized what was wrong -
In the newly created Xib, even after you assign the File's Owner to the ViewController there is an additional step which you need to take.
You need to have the main View's referencing Outlet set to the File's owner as well. The easiest way to do this is to Drag the "+" sign on the referencing outlet(From the Connections inspector) to the "File's Owner" in the Document Outline. After this you just need to click on "view" which pops up and you should be good.
Hope that helps you or anyone else facing the same problem
Need more info to answer, I can give few possibilities.
Check if the class name is mapped properly in your identity inspector.
And check your connections too. If your view is mapped in xib., etc.
If your running the app in OS below 6.0 & built with features such as Auto layout, it leads to crash.
There are multiple possibilities.
Hope this gives an insight.
Check if your nib is added to the application bundle. You can do that by selection you project file->Build Phases->Copy Bundle Resources.
If it is not there, add it.
I had the same issue yesterday and this was the problem.
I hope it helps.

deploy to device results in frankenstein binary

I'm unsure if this is relevant to my question, but I'll start at the beginning: In my project I have a view controller which is instantiated dynamically by class name, like this:
NSString* className;
...className is set to a valid class name, e.g. "someViewController"
Class c = NSClassFromString( className );
UIViewController* vc = [[c alloc] init];
In the current build of the project, someViewController is simply a specialized UIViewController. However, in an old build of the project (which was previously deployed to my device), the view controller of type someViewController was a specialized UITableViewController.
I spent a bunch of time this morning trying to understand why when I ran the build on the device (deploy from XCode), it would crash with an odd call stack and a console message:
[someViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xeb62a0
With much experimentation I found that if I swapped out the someViewController with any other view controller I couldn't repro the problem. And if I renamed someViewController to someViewController2 I couldn't repro the problem. The problem was with the symbol name someViewController. Then it dawned on me that someViewController USED to be a UITableViewController and would have had the tableView:numberOfRowsInSection: implemented.
In any event; deleting the app off of the device and having XCode deploy a clean copy fixed the issue.
What I want to know is, why? How? I guess I've known in the back of my mind for a while that XCode does funky stuff when deploying - I've had issues before where old resources stick around in the deployed bundle after they've been removed from the project. But I wouldn't have expected there to be issues with Objective-C types.
Simply renaming a .h and .m file and then introducing a new .h and .m with the same name will cause problems. Not to xcode, but to you. Best is to copy files to a directory like /tmp, delete them from the project, later add them to the project as new with a different name.

Reasons for an IBOutlet to be nil

What are the reasons why an IBOutlet (connected) could be nil?
I have one in may application which is always nil, even if I recreate everything from scratch (declaration and control).
It could be that your nib is messed up, but I find a common reason is having two instances where you think you only have one, and the one you're using in your code is not the one you connected.
If you've also defined a loadView method that creates the view, it is possible based on how you initialize it. If you initialize it using alloc-init and the nib name is not the same as class name, then you can have a case where the outlet is nil. But Chuck's answer seems more reasonable to assume.
One reason I just got stung by: If the nib file is not included in the target resource files for some reason (like you had the targets unchecked when you added it to the project), Xcode doesn't throw an error but all the outlets from that nib are going to be null...
One possibility:
Suppose the IBOutlet container is a singleton object with a function like:
+ (singletonObject*) sharedInstance {
if(!gGlobalSingletonPointer) {
gGlobalSingletonPointer = [[singletonObject alloc] init];
}
return gGlobalSingletonPointer;
}
You create the singleton object "on demand" if it doesn't already exist.
You save a global pointer to it, as you create it, in that function.
If you also instantiate such an object in InterfaceBuilder, and connect its outlets, this object will be created without sharedInstance being called. If you subsequently call sharedInstance, a new object is created (sans IBOutlet connections).
The solution is to update the global pointer in singletonObject's init or awakeFromNib function.
Are you using a UINavigationController?
If so, open your MainWindow.xib in IB and make sure that your root controller's nib name is set correctly in the Attributes Inspector.
Why would this not be set correctly? One reason is the 'rename' refactoring doesn't update this, and then the internals won't find the nib with which to wire your UI. Or you renamed the nib yourself, and didn't update this field.
Are you doing something unusual with File's Owner? If you're not in one of the situations where the nib is loaded automatically (main nib loaded by application or nib loaded by view controller, document, or window controller), then you have to load the nib programmatically.