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.
- Drag an object into the xib in Interface Builder.
- Set the type to whatever you want for the class name in the Class Identity section of the Identity Inspector.
- Under the Classes section in the Library, select your class and add any outlets you want.
- Add UI objects and connect the outlets from the instance you added in the xib as normal.
- 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
- 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.
精彩评论