开发者

Monotouch: How to update a textfield in AppDelegate partial class?

I have a text开发者_运维问答field (created using IB) that has an outlet connected to App Delegate. Accessability is enabled.

I have a class for IAP, where I need to update that textfield. It is not visible from my code.

How do I do this?


This is pretty simple to do, you need to do 2 things:

1: Expose the outlet in a public property, inside your appdelegate:

public class AppDelegate : NSObject {
    public UITextField PublicField {
        get {
            return outletName;
        }
    }
}

2: Access your AppDelegate from another class:

public class OtherClass : NSObject {
    public void SomeMethod () {
        var ad = (AppDelegate) UIApplication.SharedApplication.Delegate;

        ad.PublicField.Text = "foo";
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜