rename xib file - objective-c

I started to create an app using tabbar app template provided in xcode. Then I wanted to change the names of the files: FirstViewController should become YellowViewControler and FirstView.xib should become YellowViewcontroller.xib. Changing the name of the xib wasn't done right. It became red as if it didn't exist in the project. So: how should I change the name of the xib files?

Use the "Refactor" tool of Xcode.
This will manage the renaming of the XIB file, the renaming of the interface & implementation of the source file containing the definition of the ViewController, the renaming of your class declarations/definitions, and any references that are used anywhere in your projects, all of this in one action.

Rename the stuff back to what their original name was (FirstViewController) and then go to the interface file for it (.h) and right click on the class name (FirstViewController) and click refactor. This should make sure everything gets changed correctly.
Source this question

Most likely your viewcontroller name still linked to previous owner therefore open the viewcontroller.xib in source code and find the owner and changed to current name. It will fix the problem right away.

Related

Need to delete the references of a .m file and then add them again iOS

I changed the prefix header name of my .h file in my Xcode project in several places, then changed the header back to its original. It seems that I have messed with my source or something. When attempting to control-click-drag from a UIButton to my .h file in order to create an IBAction,
I get the following error:
Could not insert new action connection: Could not insert source code into document at
URL file://localhost/Users/Myuser/file/filename/projectname/SGLoginHomeViewController.m
because it does not contain a class interface for the class named SGLoginHomeViewController
Once again I am attempting to create a new IBAction in the class file SGLoginHomeViewController.h
I believe that I need to delete the references and then add them back, but how do I do this?
Follow this:-
To Delete reference:_
1. Right click on your .h or .m file.
2. Click on "Delete". A pop up will open.
3. Click on "Remove reference". Your file reference has been deleted.
To add it again:-
1. Right click on your project.
2. Click on "Add files to 'YourProjectName'".
3. A pop up will open. Select you file & Click Add.
Note:- Make sure "Copy items into destination group's folder(if needed)" is unchecked.

Changing class of object in XCode

I am trying to give an object in the interface builder a custom class. When typing in the class name in the Identity Inspector it automatically finishes the line as its already present in the dropdown list of available classes.
However after entering the class the page comes up with a padlock image and clears the class name.
What is the cause of this and how can I rectify it?
firstly, you must reload xcode
if it not work you must have subclass associate with it in IB
Create CustomClass:UITableViewCell then drop UITableViewCell to IB and then just type the name
If dropdown list not display, reload Xcode
Assuming you've specific the right IB object (e.g., a dynamic cell prototype, whose default class is UITableViewCell) and your custom class is defined correctly (as a subclass of UITableViewCell, itself), then I have a couple of thoughts of what you might try:
Sometimes exiting and restarting Xcode is often enough.
Also try selecting "Clean" from the "Build" menu (or press shift+command ⌘+K).
In the worst case scenario, sometimes you have to exit Xcode and delete the DerivedData folder and then restart Xcode. To find the derived data folder, press command ⌘+, (comma) and go to the last tab, "Locations", and click on the arrow next to the "Derived Data" folder:
Having pulled up that folder in Finder, quit Xcode, delete the contents of that DerivedData folder in Finder (after quitting Xcode), and then restart Xcode and try again.
I think I have found the solution (not sure if I have found a fix for the actual problem or just found a way around it)...
I changed the Lock dropdown setting to Nothing and it now allows me to set my own custom class to the Object in the file.
Whats strange is that the document lock was previously set to Inherit (Nothing) anyway so not sure what the difference is here.

Cocoa failed to load window nib file when nib is localized

I'm trying to create and show new window in my simple Cocoa application:
myWindow = [[MyWindowController alloc] initWithWindowNibName:#"MyWindow" owner:self];
[myWindow showWindow:self];
It's working well with basic nib file without localization, but as soon as I turn on localization for this specific nib file (using Xcode "localize" option available form file inspector), the application gives me this error when executing the code above:
-[MyWindowController loadWindow]: failed to load window nib file 'AuthWindow'.
Should I change the way I'm initializing my window controller when using localized nibs? It fails only when nib containing a window is localized (with just one language - English), when there is no localization configured - the window is loaded and appears on the screen as it should. I can't find the right answer, I'm new to Cocoa on OSX, but have some experience with CocoaTouch and developing for iOS.
I restarted Xcode and the error went away...
I don't know... but whatever...
initWithWindowNibName: can locate a .nib file in a localization directory such as en.lproj/. The problem is, sometimes Xcode forgets to compile a .xib file (an Interface Builder file in XML format, which you usually play with) into a .nib file, or a binary format - especially when the .xib file is just localized by clicking "Localized..." button.
If you open $build_dir/Your.app/Contents/Resources/$locale.lproj you will find some xibs only copied from the source directory.
Relaunching Xcode will resolve the situation, while I'm not sure what the cause is and why relaunching does the trick.
It's an old question, but I found a different solution than those above. In the nib in question, go to the identity panel and make sure the nib's target membership is checked.
I had an error like this. What solved it for me was to make a backup copy of the xib file, delete it from xcode, restart xcode, then add it back. Go figure...

XCode deployment error: 'NSInvalidArgumentException', Could not find a storyboard named 'MainStoryboard'

Like many of the prior 'MainStoryboard missing in NSBundle' questions, I've got the same prompt but have found no issue with naming and no issue with if the storyboard exists within an area XCode likes.
All the pointers lead to the same file, I've changed my .plist a good 5 times to make it responsive to the same call as found in Build Stages. Now I'm all kinds of tired of this crap because I just want to program, not debug compiler screw ups.
It happened in an instant and now I've been a day and a half without an interface that works. How should I proceed?
I got the following similar error in XCode 4.3.3:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'Could not find a storyboard
named 'MainStoryboard'
I fixed it by doing the following:
Make sure your -info.plist has Main story board file based name = MainStoryboard
Right Click on your Story Board file in Xcode and select Delete then References Only
Right Click on your project and select Add Files to [Your Project]
Navigate to the story board file, found in the en.lproj folder in your projects directory and add it
Clean, Recompile and Run and you should find it works.
Got the idea from this SO post: XCode 4.2 MainStoryBoard Not Found
Just as a reference to other first timers like me reading through all the SO questions about missing storyboards:
Don't put ".storyboard" at the end of your file name in your plist file. It should look like this:
Main storyboard file base name: MainStoryBoard
When you create a new *.storyboard file, Xcode (version to date) doesn't automatically add it into your build resources. To fix this you must add the file under "Copy Bundle Resources".
Select the Xcode project icon and navigate to: Targets > Build Phases > Copy Bundle Resources
Click the + button at the bottom to add the storyboard file.
After cleaning my Projekt i have every time this Problem......
My solution is:
move the Main.Storyboard intro trash.
Then "Add Files" select your soryboard, after moving the Main.stpryboard from trash zo your desktop.
and, voila. The Error ist gone.
Considering that there is not too much information about your problem, My best bet would be to go to the package Info, and see if the Main Storyboard is set to whatever your main storyboard is.
As of iOS 9 use just "Main" for storyboard name, worked for me.
Ralph Willgoss's steps didn't work for me. I managed to solve it by copying all the viewcontrollers in the storyboard, deleting it (Move to Trash, not Remove Reference), making a new one (rightclicking the project folder and clicking New File, selecting Storyboard) with the same name as the one I deleted and then pasting the copied contents into it.

There is no .xib file when I create a new "Empty Application" in XCode

I am working through the Big Nerd Ranch Guide (2nd Ed) for iOS Programming using Xcode version 4.2.
For the very first project I'm asked to create a new project which is a "Window-based Application" the description for which reads "This template provides a starting point for any application. It provides just an application delegate and a window". The "Window-based Application" option was not available to me in XCode 4.2 but I did see the option to create a "New Empty Application" which has the same description ("This template provides a starting point for any application. It provides just an application delegate and a window")
When I create the project I'm supposed to have a MainWindow.xib file but that does not show up at all in my project? Help please
When you create the project, don't forget to uncheck the option "storyboard". Once you uncheck it, you can see the xib files.
I am using the same book, had the same problem but I figured how to fix it.
Create a new xib file by
right click Quiz folder -> New File -> iOS -> User Interface -> Window -> click Next
click the Window.xib file then find an Object and drag it under Objects -> select the third tab on the right -> change this class to AppDelegate
click File's Owner -> change this class to UIApplication -> click the 6th tab and connect delegate to Window
goto AppDelegate.h and put IBOutlet in front of UIWindow *window;
goto Window.xib again and connect window under Outlets to Window.
Also in plist file add a row
key - Main nib file base name
type - string
value - mainwindow
Hope this helps.
If you create a empty project and do want to use storyboading, then do:
create empty project
add new file (storyboard)
make sure to add a correct entry in your app-info.plist file. (Just create a simple project with storyboard and look-up the key there in the app-plist).
throw a view controller on the board, and off you go.
Like this you have a nice clean project, with the use of the storyboard feature.
Please read this in the official Forum to the Book. BNR posted a project that you can use as your default Project for all Chapters in this Book. They created a small Project that looks as if you created an empty project with the XCode version before iOS5 was released.
http://forums.bignerdranch.com/viewtopic.php?f=74&t=1817
regards
Thomas
You can also create a MainWindow.xib afterwards:
File > New > File >
There should be a Window.xib. If not, creat an empty .XIB file and drag a window (UIWindow) into your Objects pane. Copy the connections as they are displayed in the book.
Hope that helps.
PS.:I recommend to not use beta software to start with iOS