2016-11-28 60 views
1

我正在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); 
} 
+0

您是否已將viewPopUp添加到您的視圖?發佈完整代碼 – HeisenBerg

+0

是的,我已經在MapviewController.designer.cs文件中添加了該視圖彈出 –

+0

[Outlet] \t UIKit.UIView ViewPopUp {get;組; } –

回答

1

隱藏在視圖中的來自DataSource的ViewController,將你的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(); 
} 
+0

公共MapFilterDataSource(串[]項,的MapViewController所有者) \t \t { \t \t \t tableItems =物品; \t \t \t this.owner =擁有者; \t \t} –

+0

它在controller.HidePopUp()上給出錯誤; –

+0

請發佈您的DataSource的完整代碼。 – HeisenBerg

相關問題