开发者

Using object instead of AppDelegate for Outlets & Actions?

In all the MonoTouch e开发者_运维问答xamples I have seen everyone is using outlets and actions on AppDelegate, yet when I've been through some objective-C webcasts I see people using an Object they drag onto XIB in Interface Builder and using that (Seems a lot cleaner). Is there just not a way to reference any Objects like that that we create? Is there a particular way to access it?

Any advice would be appreciated,

thanks


Sure you can.

  1. Drag an object into the xib in Interface Builder.
  2. Set the type to whatever you want for the class name in the Class Identity section of the Identity Inspector.
  3. Under the Classes section in the Library, select your class and add any outlets you want.
  4. Add UI objects and connect the outlets from the instance you added in the xib as normal.
  5. Add your class to MonoDevelop and make it a partial class derived from NSObject.
    • The outlet(s) will be in the generated part of the partial class in the .designer.cs file for the xib
  6. Add whatever code in your class to interact with the outlets pointing to the objects added in Interface Builder

I added a small sample here that creates a class named "SomeClass" which is instantiated via the xib, along with an outlet to a UILabel, with the text for the UILabel being set in the SomeClass file I added in MonoDevelop.


No there is no other way to access the objects from Interface Builder. Even that Object will need an outlet to connect to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜