這是我遇到的場景。我有一個用戶名作爲其中一個字段的登錄屏幕。用戶可以使用下拉列表選擇一個用戶(通過按鈕實現 - 模擬下拉箭頭,彈出窗口控制器和表格視圖)。我有一個控制器(UserNameController),它具有獲取用戶名並將其綁定到其中的表視圖的邏輯。在tableview中選擇一行後更新textfield Xamarin.IOS
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);
和在UserNameController:所述UserNameController經由具有文本字段,並使用下面的代碼的下拉按鈕ViewController.cs稱爲
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);
}
}
現在我該如何在viewcontroller的textfield中顯示選定的用戶名並關閉彈出窗口?
謝謝! Sid