views:

205

answers:

1

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?

+6  A: 

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: step 1

Step 2) Add a UILabel Control to your View: step 2

Step 3) Select "File's Owner": step 3

Step 4) Select the Identity Inspector (CMD + 4) and add a new Class Outlet: step 4

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

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.

Pselus
1 for the effort
Chris S
Another one for effort.
Eduardo Scoz
And another one
Simon Söderman