gpt4 book ai didi

c# - PickerView 工具栏的完成按钮不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 15:50:32 24 4
gpt4 key购买 nike

添加到 pickerview 工具栏的完成按钮,但是点击完成按钮点击事件不起作用。

    public override void ViewDidLoad(){
myPickerView = new UIPickerView (RectangleF.Empty){
AutoresizingMask = UIViewAutoresizing.FlexibleWidth,
ShowSelectionIndicator = true,
Model = model,
Hidden = true,
BackgroundColor = UIColor.Clear
};

toolbar = new UIToolbar();
toolbar.BarStyle = UIBarStyle.Default;
toolbar.Translucent = true;
toolbar.SizeToFit();

// Create a 'done' button for the toolbar and add it to the toolbar
UIBarButtonItem doneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done,
(s, e) => {
Console.WriteLine ("Calling Done!");
txt_RegistrationType.Text = selectedType;
txt_Email.ResignFirstResponder();
txt_UserName.ResignFirstResponder();
txt_Password.ResignFirstResponder();
txt_PhoneNumber.ResignFirstResponder();
txt_ConformPassword.ResignFirstResponder();
});
toolbar.SetItems(new UIBarButtonItem[]{doneButton}, true);
model.PickerChanged += (sender, e) => {
Console.WriteLine("selected vlaue {0}",e.SelectedValue);
txt_RegistrationType.Text = e.SelectedValue;
};

this.myPickerView.AddSubview (toolbar);
myPickerView.Frame = PickerFrameWithSize (myPickerView.SizeThatFits (SizeF.Empty));
View.AddSubview (myPickerView);
myPickerView.AddSubview (toolbar);
}

点击选中的项目

它显示 pickerView“PickerView.Hidden = false”,它显示选择器 View 和带有完成按钮的工具栏。单击工具栏上的完成按钮时,其单击事件不起作用。

请让我知道如何在点击完成按钮上获取事件。

最佳答案

首先,我想指出您两次将“工具栏”添加到当前的“UIPickerView”。一旦:

this.myPickerView.AddSubview (toolbar);

还有一次:

myPickerView.AddSubview (toolbar);

其次,为什么是工具栏?它只会增加项目的复杂性和依赖性。

我的建议是废弃整个代码块,并在此 View 上制作两个单独的控件:

  1. 一个按钮
  2. 一个 UIPickerView

    public override void ViewDidLoad()
    {
    UIButton button = new UIButton (new RectangleF (5, 5, frame_width, 30));
    button.TouchUpInside += Method;

    UIPickerView pickerView = new UIPickerView (new RectangleF (5, 45, frame_width, 180));
    pickerView.Model = model

    this.View.AddSubviews (new UIView[]{button, pickerView});
    }

    void Method (object sender, eventargs e)
    {
    Console.WriteLine ("Done");
    /*If you want to make the pickerView disappear,
    you can add a pickerView.Hide() here, and then call a method
    to redraw the controls on the current view.*/
    }

希望对您有所帮助。祝你好运!

关于c# - PickerView 工具栏的完成按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26065940/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com