我正在Xamarin iOS平臺上工作,並且我打開了一個有TableView
的視圖。我想隱藏彈出式視圖時RowSelected
委託方法調用如何在點擊tableview時隱藏視圖在Xamarin iOS中委託?
這裏是我的代碼:
在TableDatasource.cs
:
using UIKit;
namespace NewProject.IOS
{
public class MapFilterDataSource : UITableViewSource
{
MainViewController controller;
protected string[] tableItems;
protected string cellIdentifier = "TableCell";
MapViewController owner;
public static string StrSelectedRow = "Intial";
int index = -1;
string[] arrCrimePerson = new string[] { "asd", "asd", "Acte asd", "asd", "a", "asd" };
string[] arrCrimeProperie = new string[]{ "asd", "asd", "Acte asd", "asd", "a", "asd" };
string[] arrStupefiants = new string[] { "asd", "asd", "Acte asd", "asd", "a", "asd" };
public MapFilterDataSource(string[] items, MapViewController owner)
{
tableItems = items;
this.owner = owner;
}
public override nint NumberOfSections(UITableView tableView)
{
return 1;
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
MapViewController.StrSelectedValue = "Autre";
MapViewController obj = new MapViewController();
obj.HidePopUp();
}
在MainViewController.cs
:
public override async void ViewDidLoad()
{
base.ViewDidLoad();
CreateTableItems();
}
public virtual void HidePopUp()
{
Debug.WriteLine("Button " + StrSelectedValue + " clicked");
viewPopUp.RemoveFromSuperview();
// This viewPopUp i want to hide but its crashing here showing error like "system.argumentnullexception value cannot be null"
}
protected void CreateTableItems()
{
List<string> tableItems = new List<string>();
tableItems.Add("asd");
tableItems.Add("sdf");
tableItems.Add("sdf");
tableItems.Add("aaa");
tblFilter.TableFooterView = new UIView(new CGRect(0, 0, 0, 0));
tblFilter.Source = new MapFilterDataSource(tableItems.ToArray(), this);
}
您是否已將viewPopUp添加到您的視圖?發佈完整代碼 – HeisenBerg
是的,我已經在MapviewController.designer.cs文件中添加了該視圖彈出 –
[Outlet] \t UIKit.UIView ViewPopUp {get;組; } –