2010-02-17 40 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