Monotouch:我如何获得此方法的可寻址性?

时间:2011-02-21 20:36:31

标签: xamarin.ios

我在不同的.cs文件中有两种方法。当尝试从文件#2访问DisplayReport(它位于文件#1中)时,我收到以下错误:

错误CS0120:访问非静态成员Prager.AppDelegate.DisplayReport()'

需要对象引用

此代码位于文件#1中:

    public partial class AppDelegate 
{
    public static string html;  
    public void DisplayReport()  {
        if(selectedSiteID == null)  {
            errorAlert ea = new errorAlert();

在文件#2中,我有这段代码:

    private void SendViaEmail()  {

        byte[] data = File.ReadAllBytes(filePath);
        NSData datas = NSData.FromArray(data);

        string[] receipients = {txtEmailAddress.Text}; 

        if (MFMailComposeViewController.CanSendMail) {

            _mail = new MFMailComposeViewController();
            if(html != null)
                _mail.SetMessageBody(html,true);  //  indicate the body is html
            else  {
                AppDelegate.DisplayReport();    //  <--error here
            }

1 个答案:

答案 0 :(得分:0)

您的DisplayReport方法需要是静态的才能以这种方式访问​​:

public static void DisplayReport() {}