How to do IBOutlets in MonoTouch?

c#, iboutlet, iphone, xamarin.ios

Solution

Pretty sure that I've figured it out so I'll post the process here for others to look at:

Step 1) Start with your empty View like this: (source: jamespwright.com)

Step 2) Add a UILabel Control to your View: (source: jamespwright.com)

Step 3) Select "File's Owner": (source: jamespwright.com)

Step 4) Select the Identity Inspector (CMD + 4) and add a new Class Outlet: (source: jamespwright.com)

Step 5) Select the Connections Inspector (CMD + 2) and you should see your new Class Outlet there: (source: jamespwright.com)

Step 6) Drag the connection to your Label on your View.

Step 7) Inside your code you populate it by typing `myLabel.Text = "My Label!"`

Hopefully that will help someone else out in the future.

Problem

I have done one iPhone app in Objective-C. When I want to link a Label to some data in that I would declare it like this: ``` @interface CityDetailViewController : UIViewController { UILabel *cityName; } @property(nonatomic, retain) IBOutlet UILabel *cityName; ``` And then when the CityDetailViewController object is created in code I would set the city name like this `[self.cityView.cityName setText:city.name];` I can't, for the life of me, figure out how to do this in MonoTouch. I tried manually creating the Outlets through Interface Builder and I tried adding this code that I found in the .designer.cs file from another project: ``` [MonoTouch.Foundation.Connect("headlineLabel")] private MonoTouch.UIKit.UILabel headlineLabel { get { return ((MonoTouch.UIKit.UILabel)(this.GetNativeField("headlineLabel"))); } set { this.SetNativeField("headlineLabel", value); } } ``` And I've tried a combination of both of those things. They don't work. The closest I can get is to actually apply the Outlet using Interface Builder, but when my View is declared I get this error: this class is not key value coding-compliant for the key headlineLabel. So I'm completely at a loss. Can someone explain this to me please?

Original source