Using .xib from other project

DarbioDarbio AUMember

Hi guys,

I have set up a xib file which has a TableViewCell defined in it.

This is working, using the following code to load the cell in a MT.Dialog Element:

    public override UITableViewCell GetCell (MonoTouch.UIKit.UITableView tv)
        var cell = tv.DequeueReusableCell("CellID") as ItemLineCell;

        if (cell == null)
            NSArray topLevelObjects = NSBundle.MainBundle.LoadNib ("TaskItemCellTest", tv, null);
            cell = Runtime.GetNSObject (topLevelObjects.ValueAt(0)) as ItemLineCell;

        cell.BindDataToCell (Title, Subtitle, Detail);

        return cell;

When I try to reference this from another project, I get the following exception:

    Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: 'NSBundle </Users/jamesdarbyshire/Library/Application Support/iPhone Simulator/6.0/Applications/4A11DD6C-141B-4C9D-9F30-1EAC2A591E86/> (loaded)' with name 'TaskItemCellTest'

I have tried including the xib file in the other project, which gives the following exception:

    Objective-C exception thrown.  Name: NSUnknownKeyException Reason: [<UITableViewCell 0x14e9fe70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Detail.

I have set up an outlet on my xib called Detail.

How do I use a xib defined in another project (referenced) in this project?


  • JeffreyStedfastJeffreyStedfast USXamarin Team Xamurai

    Hi Macropus,

    I just want to make sure I understand the question correctly, so if this isn't right, please correct me:

    1. You have a MonoTouch Library Project, let's call it ProjectA, that has a custom .xib file defining a UITableViewCell.

    2. You've created a new MonoTouch Project that you've configured to reference ProjectA.

    In ProjectA, make sure that the Build Action for the .xib is "InterfaceDefinition" (you can check this by right-clicking on the file in the Solution Tree and then look for the Build Action menu, which should open a submenu with radio buttons next to a list of possible values). By default, it should already be set to InterfaceDefinition.

    If that is set to InterfaceDefinition, then it should Just Work(tm). If not, then there might be a bug in MonoDevelop somewhere.

    For MonoTouch Library Projects, MonoDevelop will embed pre-compiled .xib files (which will end up with a .nib file extension) into the compiled .dll assembly. When the main (.exe) MonoTouch project is built, one of the build steps is to extract all of the .nib files (and other BundleResource files) from the library .dll into the appropriate location into the final directory.

    Could you check that the .app directory contains the .nib file for your custom UITableViewCell when the .xib is part of the library project (i.e. your original attempt at having this work).

    In your second attempt at getting this to work, adding the .xib to the main .exe project, I'm not sure why it's not working. A quick Google search turns up some similar errors on which suggest that perhaps the .xib is trying to reference some class or another that it can't find?

    Unfortunately I'm not very knowledgable about .xibs themselves.

  • DarbioDarbio AUMember

    Hi Jeff,

    I have done this - the only difference being that Project A and Project B are from the Universal App Template in MonoDevelop.

    The .xib is in Project A, which is an app.

    I then have Project B, which references Project A, and has it's own AppDelegate defined, which inherits from AppDelegate in Project A.

    This is so that the same app can be 'white labelled' without having to change anything apart from the AppDelegate.

  • DarbioDarbio AUMember

    Hi Jeff,

    I moved the xib files out from Project A into a Library project and this seems to be working.

    It seems that, when you reference an application project, MT does not include files from the referenced project - but it does when it's a library template.


Sign In or Register to comment.