gpt4 book ai didi

ios - 在 Xamarin iOS 中单击 tableview Delegate 时如何隐藏 View ?

转载 作者:行者123 更新时间:2023-11-29 11:51:41 26 4
gpt4 key购买 nike

我在 Xamarin iOS 平台上工作,我打开了一个包含 TableView 的 View 。我想在 RowSelected 委托(delegate)方法调用时隐藏弹出 View

这是我的代码:

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);
}

最佳答案

要从 DataSource 隐藏 ViewController 中的 View ,将 ViewController 的实例传递给 DataSource(通过构造器)

public class MyDataSource : UITableViewSource
{
MainViewController controller;
List<string> tableItems

public ProgramArticlesTableSource (List<string> tableItems, MainViewController controller)
{
this.tableItems = tableItems;
this.controller = controller;
}
......

然后调用RowSelected中的HidePopup方法。

public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
controller.HidePopUp();
}

关于ios - 在 Xamarin iOS 中单击 tableview Delegate 时如何隐藏 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40844505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com