Using custom UI views from library in interface builder - iphone

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.

Related

How to properly import subclass frameworks into projects

I have a question regarding importing subclasses into projects. We often find useful subclasses on GitHub that we can use. In my case it's just a Swift Xcode project which is a Swift port of an Objective-C subclass.
Contains what you see below.
There's no storyboard or anything so I'm wondering why the product folder at the bottom has a SiriWaveformView.framework suitcase icon but there is no framework with this name in the Finder.
Is this technically a framework/API? Do I simply copy SiriWaveformView.swift and SiriWaveformView.h into my own project? How do I connect an interface object to this class?

Unknown class <MyViewController> in Interface Builder file + Localization issue

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.

How to Apply Style to Iphone application

I like to have uniformity in my application style for my mobile.How to apply the styles to my control in the Iphone app ..Something similar to android resource files.. Even i hope thats one of the good pattern to follow in the application develovpment
Buttons can be styled by using
creating a custom button.
Custom views can be created using Interface builder or via code inheriting the UIview. A sample tutorial can be found here
You can create custom uitableview and uitableview cells too.
Resource files in android application is what Interface builder provides you in Xcode to create xib (nibs) for your ui layout.

Interface Builder can't see classes in a static library

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.

Packaging a Bundle with a static library

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.