3
votes

I am creating a custom iPhone View in MonoTouch through the interface builder in XCode (In monodevelop New File -> MonoTouch -> iPhone View).

When selecting a new iPhone View it creates an xib file, but no .h file is created, so how can I create outlets?

I usually drag an outlet from my label/button etc. to the .h file, but since it doesn't exist for this view, I don't know how to create the outlets.

Can someone point me in the right direction, since all articles on google are for the old versions, where outlets where created differently.

2
What do you mean by "selecting a new iPhone View it creates an xib file?" do you mean dragging a view from the library to the storyboard? - jhilgert00
No, I mean in MonoDevelop: Add File -> MonoTouch -> iPhone View - Dofs

2 Answers

2
votes

When you double-click a .xib in MonoDevelop, MonoDevelop will generate header files for your [Register]'d C# classes that subclass ObjC types and export them to a temporary Xcode project, where you can use Xcode to drag&drop Outlets and Actions.

Adding a new iPhone View file (.xib) does not auto-create any backing C# classes for you, it just creates the .xib, therefore MonoDevelop does not autogenerate any header files for you when you double-click the .xib.

When Xcode launches, you can manually create some Objective-C headers for this .xib and drag&drop outlets or actions to it (or you can create C# classes in MonoDevelop before double-clicking the .xib). When you switch back to MonoDevelop, MonoDevelop will "import" the header files, translating them into the equivalent C#.

While in Xcode, you can also add .xib's there and MonoDevelop will import those as well.

1
votes

The Xamarin documentation has a good tutorial on this. There is a section for Adding Outlets and Actions to the UI using Interface Builder in Xcode4

Adding an Outlet In order to create the Outlet, use the following procedure:

  1. Determine for which control you want an Outlet.
  2. Hold down the Control key on the keyboard, and then drag from the control to an empty space in your code file after the @interface definition.