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

a 夏天 提交于 2019-12-06 12:42:07

问题


I have a textfield (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?


回答1:


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";
    }
}


来源:https://stackoverflow.com/questions/4715488/monotouch-how-to-update-a-textfield-in-appdelegate-partial-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!