2013-05-02 15 views
1

所以,我試圖當用戶點擊「StyledStringElement」打開電子郵件接口 - 要做到這一點,我一直在呼籲對竊聽事件還我已經獲得了錯誤 -StyledStringElement「抽頭」事件

「錯誤CS1502:用於 `MonoTouch.Dialog.Section.Add(MonoTouch.Dialog.Element)最好重載的方法匹配」具有一些 無效的參數(CS1502)」

「錯誤CS1503:參數#1' cannot convert無效 '表情輸入 `MonoTouch.Dialog.Element'(CS1503)」

我使用的代碼 -

 section.Add(new StyledStringElement("Contact Email",item.Email) { 
      BackgroundColor=UIColor.FromRGB(71,165,209), 
      TextColor=UIColor.White, 
      DetailColor=UIColor.White, 
     }.Tapped += delegate { 
      MFMailComposeViewController email = new MFMailComposeViewController(); 
      this.NavigationController.PresentViewController(email,true,null); 
    }); 

是什麼原因造成這個錯誤我該如何解決它?

回答

2

您需要初始化「StyledStringElement」分別

例如:

var style = new StyledStringElement("Contact Email",item.Email) { 
      BackgroundColor=UIColor.FromRGB(71,165,209), 
      TextColor=UIColor.White, 
      DetailColor=UIColor.White, 
     }; 

style.Tapped += delegate { 
      MFMailComposeViewController email = new MFMailComposeViewController(); 
      this.NavigationController.PresentViewController(email,true,null); 
    }; 

section.Add(style); 
0

new X().SomeEvent += Handler的返回值是void,所以你不能添加在你的部分。

不幸的是,C#正式**不支持在分配對象初始化器(Assigning events in object initializer)事件,所以你不能這樣做既不:

new X() { 
    SomeEvent += Handler, 
}; 

如果你仍然想實例,並在同一高度的時候,你能來最接近的是

StyleStringElement style; 
section.Add(style = new StyledStringElement("Contact Email",item.Email) { 
     BackgroundColor=UIColor.FromRGB(71,165,209), 
     TextColor=UIColor.White, 
     DetailColor=UIColor.White, 
    }); 

style.Tapped += delegate { 
     MFMailComposeViewController email = new MFMailComposeViewController(); 
     this.NavigationController.PresentViewController(email,true,null); 
}; 

**當我說正式,那是因爲我記得有些人得到了它在單聲道C#編譯器的一些分支機構工作。