0

私はすぐに夢中になる問題に直面しています。私はpickermodel、数字で を持っています。ピッカーから番号を選択し、写真を撮ります。すると、ショーで同じ番号が選択されているdismissmodalviewcontrollerことがわかりますが、コードでアクセスしようとすると、空です。私は取り組んでいますが、この問題はiOSに関連していると思います。viewcontrollerpickermodelXamarin.iOs

//viewcontrollerからのViewWillAppear

public override void ViewWillAppear(bool animated)
{
        base.ViewWillAppear(animated);
        sitepickerModel = new SitePicker();
        sitepickerModel.Sites.Add(" ");
        Console.WriteLine(this.Title);
        //gets sitesID with the name of Title.
        sitesID = localDb.GetSitesID(this.Title);
        //Adds sites ID(number) to pickermodel
        if (sitesID != null)
        {
            foreach (var s in sitesID)
            {
                sitepickerModel.Sites.Add(s);

            }
        }
        //assigns pickerview to the class pickerModel
        pickerSitesID.Model = sitepickerModel;
        sitepickerModel.ValueChanged += SitepickerModel_ValueChanged;
        siteLabelTxt.Text = sitepickerModel.SelectedSite;
        syncronizeSegment.SelectedSegment = 1;

        if (sitepickerModel.SelectedSite != null)
            Console.WriteLine("View:" + sitepickerModel.SelectedSite);

    }

//CLass UIPickerViewModel
public class SitePicker : UIPickerViewModel
{
    public event EventHandler<EventArgs> ValueChanged;

    //items to show up in the picker
    public List<string> Sites { get; private set; }
    public string SelectedSite
    {
        get
        {

            if (selectedIndex > Sites.Count && selectedIndex > 0)
            {

                selectedIndex = Sites.Count;
                return Sites[selectedIndex];
            }
            else if (selectedIndex == 0 )
            {

                return " ";
            }
            else if (selectedIndex== Sites.Count) {
                selectedIndex = Sites.Count - 1;
                return Sites[selectedIndex];
            }
            else {

                if (Sites[selectedIndex] == " ")
                    return " ";
                else
                    return Sites[selectedIndex];
            }
        }
    }
    int selectedIndex = 0;
    public SitePicker()
    {
        Sites = new List<string>();
    }

    public override nint GetRowsInComponent(UIPickerView pickerView, nint component)
    {

        return Sites.Count;
    }
    public override string GetTitle(UIPickerView pickerView, nint row, nint component)
    {
        if (NoItem())
            return " ";
        var item = Sites[(int)row];
            return item;

    }

    public override nint GetComponentCount(UIPickerView pickerView)
    {
        return 1;
    }

    public override void Selected(UIPickerView pickerView, nint row, nint component)
    {
        selectedIndex = (int)row;

        if (ValueChanged != null)
        {
            ValueChanged(this, new EventArgs());
        }
    }
    bool NoItem(int row = 0) 
    {
        return Sites == null || row >= Sites.Count;
    }
}

}

4

0 に答える 0