对于“actionSheetAlert",后面是什么(动作)=> [英] For "actionSheetAlert", what's after (action) =>
问题描述
我正在使用 Xamarin 的 ActionSheet Alert 功能并按照官方网站的说明进行操作.网站给出的样本显示为
I'm using Xamarin's ActionSheet Alert function and following the instruction from official website. The sample given by website is shown as
actionSheetAlert.AddAction(UIAlertAction.Create("Item One",UIAlertActionStyle.Default, (action) => Console.WriteLine ("Item One pressed.")));
在(action) =>
之后,它只展示了我们如何在这里添加一个函数,即(action) =>Console.WriteLine(第一个被按下.")
After (action) =>
, it only shows how we can add one function here, which is (action) => Console.WriteLine ("Item One pressed.")
如果我想添加更多操作怎么办?我可以只使用 (action) =>{......}
?或者我可以使用 (action) =>function1()
?你能告诉我更多的例子,我可以在 (action) =>
之后做吗?
What if I want to add more actions? Can I just use (action) => {......}
? Or can I use (action) => function1()
? Could you please show me more examples that I can do after (action) =>
?
推荐答案
这是 UIActionSheet 的示例代码,应该可以帮到你.
That's sample code for UIActionSheet, it should can help you.
using System;
using System.Collections.Generic;
using UIKit;
namespace TestActionSheet
{
public class SimpleSheet
{
public delegate void SelectedHandler(string selectedValue);
public event SelectedHandler Selected;
private UIActionSheet actionSheet;
public SimpleSheet(List<string> optionList)
{
actionSheet = new UIActionSheet("SheetTitle");
foreach (string str in optionList)
{
actionSheet.Add(str);
}
actionSheet.AddButton("Cancel");
actionSheet.Clicked += (sender, e) =>
{
if (e.ButtonIndex < actionSheet.ButtonCount - 1)
{
if (null != Selected)
Selected(optionList[(int)e.ButtonIndex]);
}
};
}
public void Show(UIView view)
{
actionSheet.ShowInView(view);
}
}
}
并像这样调用这些代码:
And invoke those code like this:
SimpleSheet sSheet = new SimpleSheet(new System.Collections.Generic.List<string>() { "option1", "option2" });
sSheet.Selected += (selectedValue) => {
Console.WriteLine("SelectedValue = "+selectedValue);
};
sSheet.Show(this.View);
希望能帮到你.
这篇关于对于“actionSheetAlert",后面是什么(动作)=>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!