How to rename a UIViewController and its xib [duplicate] - objective-c

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.)

Related

Xcode 6 OS X storyboard multiple User Defaults Controllers bug with multiple scenes?

Maybe I'm just doing something wrong here but I've ran into an issue that I can't find a solution for. Maybe someone has seen this?
Using Xcode 6, I create a new project with Objective C & Storyboards.
In the interface builder view, I place a text field on the view that comes with the storyboard and bind it to the 'Shared User Defaults Controller'. Everything works fine.
I add a second view controller. This creates a new scene. I place a text field on this view and bind it to the 'Shared User Defaults Controller' and here's the issue:
A 'User Defaults Controller' gets created in the scene. If I expand the dropdown list for 'Value' 'Bind to', there are now 2 'User Defaults Controller' objects in the list. The binding doesn't seem to work as the value doesn't get stored in the preferences file.
Did I do this wrong? Or is it a bug in OS X storyboards on Xcode 6?
Yes, it is a bug in Xcode 6 with Storyboards. I found a workaround: edit the storyboard manually.
First bind an item to the shared preferences on one scene. Then close the storyboard and edit it as source (edit the xml directly).
Find the line representing the shared user preferences instance. It should look something like that:
<userDefaultsController representsSharedInstance="YES" id="a6K-Ly-rL1"/>
You can then copy this line in each scene, in the objects array, in the xml directly.
You must edit the id of each shared preference instance added manually because a storyboard file cannot have more than one object with the same id. Simply changing one character at random in the id string is enough.
My workaround is to add an NSObject to the storyboard scene and use my custom class
#objc(SharedUserDefaultsControllerProxy)
public class SharedUserDefaultsControllerProxy: NSObject {
lazy var defaults = NSUserDefaultsController.sharedUserDefaultsController()
}
then bind on self.defaults.values.

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.

Starting an ipad app, XCode doesn't do as it should

So according to this tutorial
"Xcode uses the product name you entered to name your project and the app. Xcode uses the class prefix name to name the classes it creates for you. For example, Xcode automatically creates an app delegate class and names it HelloWorldAppDelegate. If you enter a different value for the class prefix, then the app delegate class is named"
However when I create my project, it doesn't create the files with my project name. So instead of "ProjectNameAppDelegate.h" I just have "AppDelegate.h". Is there a reason why XCode wouldn't create the proper files I need and how do I fix it?
I also don't have a ViewController.xib file which most online tutorials say I should have. I do have a "MainStoryboard.storyboard but I'm not sure if that counts as the same thing.
The tutorial you mentioned is on an old Xcode. The latest Xcode wont create appDelegate and ViewController classes by prefixing project name as you said like ProjectNameAppDelegate.h. It simply create AppDelegate.h only. It is not a bug.
In the above figure you can see that i have selected Use StoryBoards, So Xcode wont create Xib files for your viewController instead it will create a storyboard only. Here you dont want xib . Storyboard is replacement for the xib. If you unselect that feature you will get xib back. As a beginner you should go through several tutorial that uses both xib and storyboards.
Adding to Anil's answer, Storyboard is a replacement for the old .xib files.

Set class on View in xib file

I have a project in Xcode 4.5 with storyboard.
I want to use a separate xib file for one piece of UI (long story) but I don't know how to connect this to the ViewController for this file. I created a separate FooViewController which is a subclass of UIViewController. However, it won't let me set this as the class for my xib (I get a beep indicating the name is invalid)
Weirdly, I can set it to some nonsense string that isn't a class in my project!? What am I doing wrong?
Rob answered in the comments to my question. Basically I was setting the class for the View and not the File's Owner as I should have been.

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

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];