Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带三个色谱柱的uipickerview-xamarin c#_C#_Ios_Xamarin_Uipickerview - Fatal编程技术网

带三个色谱柱的uipickerview-xamarin c#

带三个色谱柱的uipickerview-xamarin c#,c#,ios,xamarin,uipickerview,C#,Ios,Xamarin,Uipickerview,我想要一个包含三列的UIPickerView,但它不工作。 我找不到错误,请有人帮忙。 代码如下: static string[] nomesPeso = new string[] { "Back Squat", "Front Squat", "OHS - Overhead Squat" }; static string[] nomesUnidades = new string[] { "Reps", "Kgs", "Lbs", "Met

我想要一个包含三列的UIPickerView,但它不工作。 我找不到错误,请有人帮忙。 代码如下:

static string[] nomesPeso = new string[]
{
    "Back Squat",
    "Front Squat",
    "OHS - Overhead Squat"
};

static string[] nomesUnidades = new string[]
{
    "Reps",
    "Kgs",
    "Lbs",
    "Metros"
};

static string[] nomesRepeticoes = new string[]
{
    "1 RM",
    "2 RM",
    "3 RM"
};

public override nint GetComponentCount(UIPickerView v)
{
    return 3;
}

public override nint GetRowsInComponent(UIPickerView pickerView, nint component)
{
    switch (component)
    {
        case 0:
            return nomesPeso.Length;
        case 1:
            return nomesRepeticoes.Length; 
        case 2:
            return nomesUnidades.Length;
        default:
            throw new NotImplementedException();
    }
}

public override string GetTitle(UIPickerView picker, nint row, nint component)
{
    switch (component)
    {
        case 0:
            return nomesPeso[row];
        case 1:
            return nomesRepeticoes[row]; 
        case 2:
            return nomesUnidades[row];
        default:
            throw new NotImplementedException();
    }
}


您可以通过覆盖
UIPickerViewDelegate
GetComponentWidth
来调整列宽:

class MyPickerViewDelegate : UIPickerViewDelegate
{
    public override nfloat GetComponentWidth(UIPickerView pickerView, nint component)
    {
        // equal size for every column
        return pickerView.Frame.Width/3;
    }
}
然后在
UIPickerView

myPickerView.Delegate = new MyPickerViewDelegate();
此代码将列平均分布。当然,您可以使用
组件
参数为每一列返回一个自定义宽度