Xamarin.Ios 下拉菜单,多选,键盘弹出功能

终于把这块弄完了,有兴趣的加我好友569653292

1、首先要键盘弹出一个下拉菜单,要知道ios没有下拉菜单这个说法,我们可以按照datePickerView的方式给它自定义,或者用tableview,这篇文章主要说一下用tableview的多选功能,先上图


好了,就是这个样子了,先定义一个tableview

UITableView utv = new UITableView (View.Bounds);
            utv.AutoresizingMask = UIViewAutoresizing.All;
            utv.Source=new myViewSource(list_leibie,ut_leibie);
            ut_leibie.InputView=utv;//这行就可以把它当作键盘弹出了


private class myViewSource:UITableViewSource
        {
            private List<string> dupLeibie;
            UITextField leibie_string = new UITextField ();
            public myViewSource(List<string>prems,UITextField ut){
                dupLeibie=prems;
                leibie_string=ut;//传递进来一个uitextfield,不然在函数里面不能更改界面的东西
            }
            public override nint RowsInSection (UITableView tableview, nint section)
            {
                return dupLeibie.Count;//返回行数
            }
            public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
            {
                UITableViewCell theCell = new UITableViewCell ();
                theCell.TextLabel.Text = dupLeibie [indexPath.Row];
                theCell.TextLabel.Font = UIFont.SystemFontOfSize (15);
                return theCell;//以上都是设置内容
            }
            string leibie = "";//用来设置文本框的内容
            public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
            {
                leibie = "";
                int rowIndex = indexPath.Row;
                UITableViewCell cellview = tableView.CellAt (indexPath);//当前行
                //判断当前行是否有标记
                if (cellview.Accessory == UITableViewCellAccessory.None) {
                    cellview.Accessory = UITableViewCellAccessory.Checkmark;
                } else {
                    cellview.Accessory = UITableViewCellAccessory.None;
                    tableView.DeselectRow (indexPath, true);
                }

//设置值,把选中的值加起来
                for (nint i = 0; i<5; i++)
                {
                    //NSIndexPath ina=tableView.cell

                    UITableViewCell cellview2 = tableView.VisibleCells[i];
                    //判断当前行是否有标记
                    if (cellview2.Accessory == UITableViewCellAccessory.Checkmark) {
                        if (leibie == "") {
                            leibie += cellview2.TextLabel.Text;
                        } else {
                            leibie += "," + cellview2.TextLabel.Text;
                        }
                    } 
                    if (leibie == "") {
                        leibie = "选择回收类别";
                    }
                }

                leibie_string.Text = String.Format(leibie);
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值