2010-02-17 18 views
4

我已經在Objective-C中完成了一個iPhone應用程序。當我想給一個標籤鏈接到一些數據我會宣佈這樣的:如何在MonoTouch中做IBOutlets?

@interface CityDetailViewController : UIViewController { 
UILabel *cityName; 
} 

@property(nonatomic, retain) IBOutlet UILabel *cityName; 

然後在代碼中創建CityDetailViewController對象時,我將設置城市名這樣[self.cityView.cityName setText:city.name];

我在我的生活中,不可能知道如何在MonoTouch中做到這一點。 我試圖手動創建通過Interface Builder的奧特萊斯和我嘗試添加該代碼,我在了.Designer.cs文件中找到從另一個項目:

[MonoTouch.Foundation.Connect("headlineLabel")] 
    private MonoTouch.UIKit.UILabel headlineLabel { 
     get { 
      return ((MonoTouch.UIKit.UILabel)(this.GetNativeField("headlineLabel"))); 
     } 
     set { 
      this.SetNativeField("headlineLabel", value); 
     } 
    } 

我都試過這些東西的組合。 他們不工作。 我能得到的最接近的是實際應用使用界面生成器的出口,但是當我的觀點是宣佈我得到這個錯誤:

this class is not key value coding-compliant for the key headlineLabel.

所以我完全不知所措。 有人可以向我解釋這個嗎?

回答

17

敢肯定,我已經想通了,所以我會在這裏發佈過程中給別人看:

步驟1)與空查看這樣開始: step 1 http://www.jamespwright.com/images/public/screengrabs/7f2b8d35406e98ee5a00a81c6346e373.PNG

步驟2)添加一個UILabel控制你的觀點: step 2 http://www.jamespwright.com/images/public/screengrabs/d757c579238ffc27acabb69c55460071.PNG

步驟3)選擇 「文件的所有者」: step 3 http://www.jamespwright.com/images/public/screengrabs/42900214063dbbc44cd4dbc2813d64eb.PNG

步驟4)選擇身份檢查(CMD + 4),並添加一個新的類出口: step 4 http://www.jamespwright.com/images/public/screengrabs/109318382a72ac9edad2bcd24e6a4b9f.PNG

步驟5)選擇連接督察(CMD + 2),你應該看到您的新類出口有: step 5 http://www.jamespwright.com/images/public/screengrabs/2a2f9f4f0cc6680e7dd8c47cabba7e24.PNG

步驟6)將在您查看連接到您的標籤。

7步)裏面你的代碼中鍵入myLabel.Text = "My Label!"

希望這將幫助別人出未來填充它。

+0

1爲努力 – 2010-02-17 11:50:06

+0

另一個努力。 – 2010-02-17 14:50:55

+0

另一個 – 2010-03-08 14:15:36