How to make IBOutlets in MonoTouch?

I made one iPhone app in Objective-C. When I want to associate a shortcut with some data, I would declare it as follows:

@interface CityDetailViewController : UIViewController { UILabel *cityName; } @property(nonatomic, retain) IBOutlet UILabel *cityName; 

And then, when the CityDetailViewController object is created in the code, I would set the city name as [self.cityView.cityName setText:city.name];

I cannot, in life, figure out how to do this in MonoTouch. I tried to manually create Outlets via Interface Builder, and I tried to add this code, which 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 tried a combination of both of these things. They do not work. The closest I can get is actually apply the Outlet with Interface Builder, but when my view is announced, I get this error:

this class is not suitable for encoding keywords for the Label keyword header.

So, I am completely at a loss. Can someone please explain this to me?

+4
source share
1 answer

I'm sure I figured this out, so I will post the process here for others to see:

Step 1) Start with your empty view: step 1
(source: jamespwright.com )

Step 2) Add the UILabel control to your view: step 2
(source: jamespwright.com )

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

Step 4) Select Identity Inspector (CMD + 4) and add a new class output: step 4
(source: jamespwright.com )

Step 5) Select the Connection Inspector (CMD + 2), and you should see your new class output there: step 5
(source: jamespwright.com )

Step 6) Drag the connection with your label to your view.

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

Hope this helps someone else in the future.

+17
source

Source: https://habr.com/ru/post/1301519/


All Articles