开发者

Monotouch: Create IBOutlet and Actions Programmatically

I need to create IBOutlet and IBActions with开发者_如何学JAVAout using Interface Builder. How can I do?


I'm not sure how you're planning on connecting an IBOutlet or an IBAction without a backing nib, but you can create the needed bits manually.

IBActions are just interface builders way of decorating a selector contract with an implementation. You can manually create a method bound to a selector with the following code example:

[Export ("someMethod:")]
public void SomeMethod (int arg) {
}

IBOutlets are just interface builders way of decorating instance variables (ivars). Ivars are exposed by the monotouch code generator as properties, so that we can lazily query the native proxy backing store and dont need to marshal the value at every transition point. You can manually create a instance variable on the proxy class with the following code example:

[Connect("varname")]
private NSObject varname {
    get {
        return ((NSObject) (this.GetNativeField("varname")));
    }
    set {
        this.SetNativeField("varname", value);
    }
}

Astute readers will notice that the MT code generator generates slightly different code:

private NSObject __mt_varname;
[Connect("varname")]
private NSObject varname {
    get {
        this.__mt_varname = ((NSObject) (this.GetNativeField("varname")));
            return this.__mt_varname;
    }
    set {
            this.__mt_varname = value;
        this.SetNativeField("varname", value);
    }
}

If you dangle any state off the object you are storing in the native field, you will need to use this construct as well, so the garbage collector sees the reference.


So i guess you want to go XIB less, you have 2 options

Adding everything by hand

or use Miguel's MonoTouch.Dialog

This 2 articles will set you up on either way.

Alex

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜