Unknown class in Interface Builder file - iphone

Why am I still getting this error when I run my iPhone app? The file is a ViewController that I have been working to delete and replace, but it just won't die. As far as I know, I don't have any reference (string or otherwise) to this file in my project.
I have deleted the related file (I'm trying to get rid of it.)
I have cleaned the project and rebuilt.
I have "Reset Content and Settings" in my simulator.
I have done a grep (grep -i -r "TheClassName" *) and nothing matches except my UserInterfaceState.xcuserstate file.
I have searched the code using XCode's Find/Replace tab.
I have double checked my Build Phases and am pretty sure it isn't in there (its a large project).
Any other ideas? I've spent way too many hours trying to figure this simple thing out; I must be missing something.
Thanks!

Check your nibs or storyboard, and make sure none of your views are set to the class!

I finally fixed the problem after trying it on multiple machines over the course of almost 2 days! I will not be thwarted!
I tracked the problem down to a call to setViewControllers on a UINavigationController which is called on initialization of the application. I was always being passed 3 objects (there are 3 panes in the navigation controller). Even though I had deleted the third object, as previously explained, three objects would always be passed in. The class type of the first two was correct, but the third would just be a UIViewController. Curiously, this view controller had a nibName which corresponded to the object file and Xib file that I had previously deleted. Of course, when view was called on this borked UIViewController, it would crash since the corresponding nib had obviously been deleted. Remember, the textual name of this object or Xib could not be found in my directory with grep, so I have absolutely no idea how in the world it came into existence when I ran my app.
So, I figured the app may not have been cleaned properly. I double and triple checked this. I even validated that my Workspace settings were correct (File->Project Settings->Advanced). The app was indeed being recompiled fresh every time.
Secondly, I started thinking that perhaps the object was being set by some other means. Working backwards, I added some breakpoints and found out that initWithCoder was being called on the parent UINavigationController--this was eventually working down to call the setViewControllers on the object and assigning the three view controllers (one of which was the offending one). I could easily see from the call stack that the Nib file that was being loaded was deserializing something offensive.
So, I started digging into my Xib file. Of course, the object name wasn't in the file (as expected since the grep didn't find anything). I deleted and recreated the portion of the Xib that included my root UINavigationController. This ended up changing the Object ID and ref within the Xib file.
Secondly, I created a new Xib and UIViewController with the same names as the one which I had previously deleted, hoping that Xcode might be happy if I created and then re-deleted them. I then compiled, re-deleted them, updated by Xib file yet again, reverified with grep that yes, indeed, nothing existed with that name.
And it worked. After spending multiple days on this issues, I'm fairly sure that there is a bug here in the interface builder, but do I want to revisit this problem to file a bug report? Absolutely not...

In my case, I solved an issue by name of Custom class name of View instead of Custom class of ViewController. By mistake i added like this for view as shown below.
It Should be for ViewController like this.
This is in my case, for you may be it's related with another component.

This happens when the view class is in a framework. Select the framework's module. Example with a CocoaPod: HSegmentControl.

Make sure when you add or rename or move files around especially in folders, that when you add them you:
A. Create Groups, not references they don't usually read in.
B. Check the boxes for the apporpriate "Product(s) or Target(s)" you want to add the source to.

Another thing to try :
I had to toggle "Inherit from Target" under the "Module" control of "Custom Class."

Related

Do i need to delete the storyboard in order to create an interface programatically?

Is it mandatory to delete the storyboard and it's reference from the plist in order to develop the interface of an app pure programatically or just making changes in app delegate file will be enough?
No, you don’t have to delete the storyboard file, but you should. We should never keep legacy code/files floating in our projects.
If you haven’t already, though, I’d suggest putting the project under source control. Commit the version with the storyboard. Then, when you’re done with your programmatic conversion, remove the storyboard and any references to it, and then commit that. That way, you’ve got the old storyboard stored away in source control, but not cluttering your actual project.
I found this guide: https://softauthor.com/ios-ui-design-programmatically-xcode-9-swift-4. It seems that deleting the storyboard is part of the process but I wouldn't doubt that you can simply just change the info.plist and the app delegate to ignore its presence without needing to delete it entirely.

XCode wont let me use a Static Library View in my xib files

I created a new project of type Static Linked Library.
I have moved the code (previously working in the app) to the library leaving all the xib files in the app.
I have changed the export directory and added the library file from the derived data folder so it gets the compiled version and links to it.
I have added the library to the bundle and have verified it is in the app using iPhone Explorer
I have verified that the xib file recognized the new view type by removing and selecting the custom view type in the custom class field of the identity inspector.
I have changed all of the #import commands to reflect the <> VS "" change and have gotten the app to compile.
however none of the methods of my custom class can be executed. and an NSLog reports that the class is its base counterpart as opposed to the custom derived class.
I am at a loss and have spend a long time converting all the code I have to work in a library. I am hoping someone can help with this.
On this issue, it turns out that Objective C's compiler does not load the categories and custom classes in the libraries by default. There are 2 ways to overcome this.
And here are your options.
Create an Activation type method on the category that will be called to "Activate" that Class or Category. This will need to be done before the application loads any nib files. And seems like a bit of a pain in the butt. This was however how I originally overcame this issue.
Add linker flags that will tell objective C to load all libraries and attach any and all Categories and Classes within the libraries before executing the application. (this will need to be done, on top of #import(ing) the correct files from their correct locations. I will provide a graphic below. and provide the flags for search purposes
-ObjC is the first one I added, but -all_load really did the trick.
I hope that others can benefit from this experience.

Changes to MainStoryboard.storyboard no longer appear in my published app

I've been working away at a project of mine, when a couple days ago I noticed that changes I was making to the MainStoryboard.storyboard weren't occurring in the published version of my app. I tried adding new components and switching many elements and still no changes. I've tried cleaning and building, but the storyboard will still not update itself to my new changes. Changes I make to the code, however, work. I can dynamically populate a text field for example.
I feel like I've done something silly and not realized it, like somehow disconnected or duplicated the storyboard (though I only see one storyboard file in my list). I'm hoping someone has some ideas so I can progress with my project. Anyone?
I had the exact same problem and it was due to localization which splits the storyboard into different ones for each language. It remains one file but xcode shows each localization in the address bar (or whatever it is called) if you select the storyboard in the file navigator.
Most likely you made changes for a storyboard language you don't use yourself for testing.

Best way to set-up an iPhone project?

Looking for the best way to set-up an iPhone project in XCode ... namely:
What is the preferred project template to start with (e.g View-Based or Windows-Based application)?
What folder structure should I create in XCode to manage the project? For example, under "Classes" is it a preferred practice to add Models, Views and Controllers sub-folders?
Any other best practices, tips, etc... would be appreciated.
Thanks
Take the most "complicated" template, based on your level of knowledge. I usually start out with the "Window-based application" myself, and add components one at a time from there.
I keep all of my code (.m/.h/.c/etc) in the "Classes" folder and only rarely add subdirectories to it. One exception is a "Generated" subdirectory for classes generated from Core Data entities.
When I create a new UIViewController subclass, I rename the resulting .xib to remove the "Controller" part; i.e. MyViewController.m gets paired with MyView.xib. (I think MyViewController.xib reads funny, as the xib isn't for the controller, it's for the view.) I also move the .xibs into their own directory next to the project file to keep things tidy.
There is no "best" template. Window-based is the most basic, while View-based starts you out with a view and a view controller.
I'm with Shaggy Frog on renaming xib files to not have "controller" in the name. However, I like to create groups to logically separate functionality, and in those groups I place view controller code along with the xib files those view controllers use. Then you know what belongs with what.
I also like a create a top-level "Application" group into which I put the app delegate, main xib file (if any), pch file, info.plist, app icon, Default.png and other things related just to the application so they are all easy to find - after you add a number of files each of those things can get lost in giant lists of stuff.
Basically organize things so you can find them, a structure that makes sense to you might not to someone else.
Window-based provides you with the most flexibility, and is probably what you want to choose after you've got a couple of projects under your belt. I find with the other templates that I'm usually removing too much code, and it would be quicker to just start from scratch.
I usually setup my projects by creating 4 subfolders under Classes: "Views", "View Controllers", "Model Objects" and "Helpers". Model objects contains all the basic object types, where as Helpers contains things like utility classes or similar. Sometimes, where relevant, I will also create a Table Cells folder underneath both Views and View Controllers. I move MainWindow.xib to the Views folder.
If the project is large, I will sometimes also have sub-folders for the Views and View Controllers based on the UITabBarController tabs. So if I have 5 tabs, then the Views folder will have 5 sub-folders, as will the View Controllers folder. I find this helps to keep everything logically together in the same place.
One other thing I do is create an Images folder under Resources, otherwise that folder gets way too cluttered very quickly.

Console won't print, only "...unrecognized selector sent to instance 0x####XX0" Runtime Errors

I'm working on an iPhone app (first real programming project) and I had two views that would go into tabs in separate applications to build them, where they work fine. Then I added them back into the main project; The tableviews bring on a crash with an numberOfRowsInSection] unrecognized selector sent to instance 0xXXXXXX so I isolated the other view to fix any errors there first. I'm using xibs.
But on the other view, when I click a Button that triggers a custom method, I get an *** -[UIViewController methodName]: unrecognized selector sent to instance 0x####XX0 just like the last one.
What also puzzles me is that the console won't print anything else except these errors; I have NSLogs() all over the place and they're not showing up, even in the appDelegate. They do however show up when they're in the main. (Because of the application life-cycle right?: then the error gets there first and I don't see my NSLogs)
The unrecognized selector messages are logged because of methods. I have all my synthesize statements and have searched questions here, but they're not like mine (I think.)
When you say you added the XIB files "back into the main project" it makes me think this is the likely area of concern.
I think it may be the case that these XIB files are still thinking they are classes in the old application (where you originally built them). I suggest:
Opening up each XIB file and removing all the connections
Then check the class name of the "file's owner" and check that this is the class in your new application. If the class names are the same in the old app as the new, change to something else and then back again.
Hopefully this will sort it. If it doesn't, try creating a brand new XIB file and then building it in the same way as you built the others. If this still doesn't work the problem is in the class; if you let us know then we can come back with further ideas in this area.
Hope that helps!
I've since removed the second view from it's xib and instead put it in the main xib, with an added UIViewController object that has it's class set to my subclass. Now it's working, and I'm moving on to the next part. I think it was that I left out UIViewController in one way or another from the xibs
As stated above, almost everything being worked out now. Thanks though and silly me for posting such a question.