I have refactored some UIView sub-classes into a static library. However, when using Interface Builder to create view components for a project that uses the static library I find that it is unaware of the library classes. What do I need to do to make the class interfaces visible to Interface Builder?
Update: The correct answer refers to dragging the headers into the 'XIB browser'. The '.h' files can be dragged from a finder window to the window area identified in this image:
alt text http://img211.imageshack.us/img211/1221/xibbrowser.png
Try dragging the static library into your xib browser in Interface Builder. I haven't tried this with a static library, but the concept is the same. When you drag header files into IB, you can access those classes.
LexH, try linking with the -ObjC flag when building your static library. That worked for me... for about a year :-) I found this post as the problem has returned with a fresh OSX install and an upgrade in xcode. But it worked in XCode 3.1.2.
David
Add the same problem as LexH. It worked only when I called a dummy class method.
The problem was that I did not add my static library to the "link binary with libraries" under target.
Strangely everything else worked.
I followed this guide to link with my static lib Create static lib
I had the same problem. Dragging the library or headers to XIB Browser didn't work. Read Class Files didn't work. So I called:
[MyLibraryClass version]; // Substitute your class name for "MyLibraryClass".
This worked. version is a class method of NSObject, so all subclasses of NSObject inherit it.
Related
I have an app with two localizations.
Usually I use 'NSLocalizedString' and keep the same source code for both localizations, but one of my ViewControllers has to look and function different for each locale.
So I pressed 'Localize..' and created two localized versions of it. Normal stuff.
Since then - on runtime I get:
Unknown class MyViewController in Interface Builder file.
and the viewcontroller is not displayed (it's a UITableViewController if it matters).
I checked in my storyboard and the custom class is still listed & linked to the view controller display. I didn't change the class name in each locale - it's still the same.
what gives here?
thanks
i experimented this kind of problem in my project and my problem was my viewcontrollers .m file was not included in the compile sources in Build Phases->Compile Sources i manually add it to the Compile Sources and problem solved for me.
i hope it will help you.
So I'm using the Static Library template included in Xcode. Right now just trying to build a simple template to see how static libraries really work.
Anyways in my static library I have two classes:
mylibrary (.h/.m) - This is simply an NSObject
modalView (.h/.m) - This is a UIViewController
The problem though is when I build the static library. The project builds the mylibrary.a file... however there is no "Headers" folder in the output. This means that when I add the library to my other project it gives "undefined" errors because it can't find the .h file for myLibrary.
Any ideas on how to fix this?
Thanks
You need to drag .h files to the new project, along with .a file
I have a bunch of scripts here:
https://github.com/drekka/dUsefulStuff/tree/master/scripts
Which I use to build static libraries and frameworks. You might find them useful in helping to assemble your library. The main (controller) build script is here
https://github.com/drekka/dUsefulStuff/blob/master/build.sh
I have 2 projects. One is a library that I am compiling to a .a file and the other is the application. The library has a class (AdFactoryView) that extends UIView that is used to display ads. Previously I was creating the AdFactoryView programmatically calling initWithFrame, now I'm trying to put the class directly into a nib and use it from there. I can find the class in the interface builder library, add it and link up the reference to an IBOutlet but when the code runs I get a message that says:
Unknown class AdFactoryView in Interface Builder file.
And the IBOutlet contains a UIView instead of an AdFactoryView. How do I get the view from my library to work correctly?
Extra information:
The application is built by importing the .a and .h files for the library. I have another project that references the entire library project directly that I use for testing, in this project AdFactoryView does not show up in interface builder.
Edit: This suddenly started working in my application project, though I still can't see the custom views in interface builder in my test project.
Using core-plot does not seem to be an easy integration task. Header path are already setup. In Interface-Builder I create an CPLayerHostingView which belongs to a View Controller which is instantiated by Interface Builder.
When the nib file is loaded I get the message:
Unknown class CPLayerHostingView in Interface Builder file
I found, that there are two different versions of that object. One for Mac-Only called "CPLayerHostingView", one for iPhone only called "CPGraphHostingView".
If following the poplular example at http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application you would use the following lines, if building an iPhone-App:
CPGraphHostingView *graphView = (CPGraphHostingView*)self.view;
graphView.hostedGraph = graph;
http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
Here is the answer ..
U can see mars' answer there
"i got it to work....ok, i added the -all_load -ObjC flag in the Target>Settings....I think this is where everyone gets confused...There are 2 places where to put the other link and header search paths, in Project Settings and in Target Settings.."
So solution is
Add -all_load -ObjC in Project settings and target settings
I had to rename CPLayerHostingView to CPGraphHostingView to get this to work after upgrading to the latest version of core plot (along with iOS 4 and the upgrade of XCode).
I think you're saying that you get this error when you load the NIB file in your app's code. In that case, the error suggests that you haven't built the Core Plot classes into your application (iPhone) or linked against the CorePlot framework and copied into the app bundle's Frameworks/ directory (OS X).
CPGraphHostingView
thank u it worked for me aswell;
3 imp things
1>perform settings for both project target aswell as application target.(make sure configuration is all configuration)
2>give correct header search path for framework library
3>learn over it::::::-)
For whatever it is worth.
Followed tutorial: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application and ended up having that same error. I looked into the CorePlot framework folder and did not find that CPLayerHostingView there, but found CPGraphHostingView inside iPhoneOnly folder.
Changed CPLayerHostingView to CPGraphHostingView in IB and error disappeared.
So, check what is in yours and use it. May work.
I have a static library that includes some xibs. These will basically be the same across projects. I'd like to include the xibs as part of the library. I can include their veiwcontrollers, reference these controllers in the calling project but then there isn't a xib to load. When I right click the xib in the library project, it can't be part of the target.
I thought about creating a CFPluginBundle but that creates a new project. I'd loose all of my IBOutlet and IBAction references. What is the best way to reuse xibs that also have outlets and actions to specific controllers?
Here more discussion about it: Can you reference Xib files from static libraries on the iPhone?
I had the same problem when I wanted to export my project as a library for other developers to use.
I found the perfect solution to my view and it seems it will answer yours too.
There is an xcode plugin that allows you to build your project as a library which includes the resources as well.
https://github.com/kstenerud/iOS-Universal-Framework
I do not know the guys that built this plugin, but it works like a charm
I'm not sure what you mean by "include the xibs as part of the library", since static libraries can't have resources--but they also aren't shipped stand-alone, so they don't need to. If you just want code re-use for your own projects, you could keep the xibs where-ever you keep the static library, and just include the xibs in any project that uses the library.
If you go the CFPluginBundle route, you can make new bundle targets in an existing project; there's nothing magic about the templates, they just take care of making dummy files and turning on the right build settings. You can copy those into a new target in your existing project and it will work just fine. That said, I'm not sure what you mean about losing IBOutlet and IBAction references, since that information is part of the xib (and the class you are using in the xib), not the project.