【发布时间】:2016-08-01 15:12:29
【问题描述】:
这是我遇到的一个场景。我有一个用户名作为字段之一的登录屏幕。用户可以使用下拉列表选择用户(通过按钮实现 - 模拟下拉箭头、弹出控制器和表格视图)。我有一个控制器(UserNameController),它具有获取用户名并将其绑定到其中的表视图的逻辑。 UserNameController 是通过 ViewController.cs 调用的,它具有文本字段和下拉按钮,使用以下代码:
var content = this.Storyboard.InstantiateViewController("UserNameLookUp") as UserNameController;
UIPopoverController popover = new UIPopoverController(content);
//popover.SetPopoverContentSize(new SizeF(80, 80), true);
popover.PresentFromRect(new RectangleF(float.Parse((sender.Frame.X + 115).ToString()),
float.Parse((sender.Frame.Y + 180).ToString())
, 80, 80), View, UIPopoverArrowDirection.Up, true);
在用户名控制器中:
public override void ViewDidLoad()
{
string[] userName = new string[10];
tblVwUserName.Source = new TableSource(userName);
}
}
TabelSource.cs 看起来像这样:
public class TableSource : UITableViewSource
{
string[] TableItems;
string CellIdentifier = "TableCell";
public TableSource(string[] items)
{
TableItems = items;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return TableItems.Length;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
string item = TableItems[indexPath.Row];
//---- if there are no cells to reuse, create a new one
if (cell == null)
{ cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier); }
cell.TextLabel.Text = item;
return cell;
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
// HOW TO SET BACK THE USERNAME TEXT FIELD IN VIEWCONTROLLER? AND CLOSE THE POPUP
tableView.DeselectRow(indexPath, true);
}
}
现在我需要如何在视图控制器的文本字段中显示选定的用户名并关闭弹出窗口?
谢谢! 席德
【问题讨论】:
标签: uitableview xamarin xamarin.ios uipopovercontroller