所以,当用户点击“StyledStringElement”时,我试图打开一个电子邮件界面--为了做到这一点,我一直在调用被点击的事件,但是我得到了错误-
错误CS1502:`MonoTouch.Dialog.Section.Add(MonoTouch.Dialog.Element)‘的最佳重载方法匹配有一些无效的参数(CS1502)
和
错误CS1503:参数
#1' cannot convert
void‘表达式为`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);
});
是什么导致了这个错误,我如何修复它?
发布于 2013-05-02 12:54:09
您需要分别初始化"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);
发布于 2013-05-02 13:30:36
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);
};
**当我正式地说,这是因为我记得有人让它在mono c#编译器的一些分支中工作。
https://stackoverflow.com/questions/16338527
复制相似问题