c# - 对于 "actionSheetAlert", (action) 之后是什么 =>

标签 c# ios xamarin xamarin.ios

我正在使用 Xamarin 的 ActionSheet Alert 功能并按照官方网站的说明进行操作。网站给出的示例显示为

actionSheetAlert.AddAction(UIAlertAction.Create("Item One",UIAlertActionStyle.Default, (action) => Console.WriteLine ("Item One pressed.")));

(action) =>之后,它只展示了我们如何在这里添加一个函数,即(action) => Console.WriteLine ("Item One pressed.")

如果我想添加更多 Action 怎么办?我可以只使用 (action) => {......} 吗?或者我可以使用 (action) => function1() 吗?你能告诉我更多我可以在 (action) => 之后做的例子吗?

最佳答案

这是UIActionSheet的示例代码,应该能帮到你。

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

然后像这样调用这些代码:

SimpleSheet sSheet = new SimpleSheet(new System.Collections.Generic.List<string>() { "option1", "option2" });
                sSheet.Selected += (selectedValue) => {
                    Console.WriteLine("SelectedValue = "+selectedValue);
                };
                sSheet.Show(this.View);

希望对您有所帮助。

关于c# - 对于 "actionSheetAlert", (action) 之后是什么 =>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41165745/

相关文章:

iOS : assign a class to inner view using storyboard

ios - 如何在 Xamarin.Forms ios 中更改工具栏图标颜色

android - 如何在 Android (Xamarin) 上为 AWS SNS 启用推送通知

ios - 如何在 Xamarin.iOS 中将 DetailTextLabel 垂直居中放置在 UITableView 的单元格中?

c# - 如何在Windows Phone 中实现横向图库

C# PropertyGrid - 检查当前是否正在编辑一个值

没有 Window_LocationChanged() 的 C# WPF DragMove

ios - 无法附加字符串 NSMutableString - 错误

html - 如何控制(在所有设备和浏览器上)字符显示为表情符号版本还是文本版本?

c# - C# 如何删除字符串的第一个和最后一个字符?