How to rename a UIViewController and its xib [duplicate]
Asked Answered
G

4

7

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.

Gelinas answered 10/9, 2013 at 7:20 Comment(10)
Have you renamed both the UIViewController class and its XIB? or just the class?Drooff
Do you want to rename both the class and the xib?Drooff
ya i want to rename both(must be different name).Gelinas
Is this what you are trying to achieve? viewController.h viewController.m viewController_nameChanged.xibDrooff
Why do you want to do it BTW? just curious!Drooff
How did you rename your UIViewController class file names?Drooff
Actually i just given a test name for my uiviewcontroller. That was not the correct name to be used in my project. After coding i tried to change the name. But the controllers showing some warnings.Gelinas
I changed file name and interface name.Gelinas
What warning message you are getting after changed file name interface name.Exonerate
Not warning messages, but warning symbols when we right click FILES OWNER.Gelinas
K
17

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.

Kenleigh answered 10/9, 2013 at 7:35 Comment(1)
Its about renaming class files and .xib with separate names.Drooff
D
2

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.

Drooff answered 10/9, 2013 at 9:6 Comment(4)
Now it showing errors.Gelinas
It showing errors where ever i used this class name. Error :"can not find interface declaration".Gelinas
Did you refactor and still still see the old names?Drooff
without using refractor i changed the class file name, interface name, and in xib file. Now it is working. Is it a proper way?Gelinas
W
2

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

Welby answered 10/9, 2013 at 10:7 Comment(0)
C
1

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

Cooperage answered 10/9, 2013 at 9:24 Comment(2)
I passed xib name and nil respectively.Gelinas
Also remember to update the class of the view controller inside the .xib file. The File's Owner proxy icon represents the view controller -- select it and set it's class to the view controller's new class name.Cooperage

© 2022 - 2024 — McMap. All rights reserved.