终于把这块弄完了,有兴趣的加我好友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);
}
}