Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Uitableview UtableView中的Xamarin iOS显示详细信息_Uitableview_Xamarin_Xamarin.ios - Fatal编程技术网

Uitableview UtableView中的Xamarin iOS显示详细信息

Uitableview UtableView中的Xamarin iOS显示详细信息,uitableview,xamarin,xamarin.ios,Uitableview,Xamarin,Xamarin.ios,我正在做一个Xamarin iOS项目。我有一个UITableView,当我点击按钮并显示链接到所选单元格的信息时,我不想选择一行。 像这样: 当我点击按钮时,我不知道如何将数据从第一个控制器传递到第二个控制器。我该怎么做 这是我的TableDataSource: private const string cellIdentifier = "ProductCell"; private ProductListViewController _controller; private List<

我正在做一个Xamarin iOS项目。我有一个UITableView,当我点击按钮并显示链接到所选单元格的信息时,我不想选择一行。 像这样:

当我点击按钮时,我不知道如何将数据从第一个控制器传递到第二个控制器。我该怎么做

这是我的TableDataSource:

private const string cellIdentifier = "ProductCell";

private ProductListViewController _controller;
private List<Product> _products;

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            ProductCell cell = (ProductCell)tableView.DequeueReusableCell(cellIdentifier);

            if (cell == null)
                cell = new ProductCell(new NSString(cellIdentifier));

            var record = _products[(int)indexPath.Row];
            cell.UpdateCell(record.Image, indexPath.Row);
            cell.Tag = indexPath.Row;

            return cell;
        }
编辑: 这是我的导航代码,我将把它放在action按钮方法中。但现在我不知道在哪里创建此方法:

var storyboard = UIStoryboard.FromName("Main", null);

            var controller = storyboard.InstantiateViewController("ProductDetailViewController") as ProductDetailViewController;
// Here I Will pass the data to the controller
            _controller.NavigationController.PushViewController(controller, true);
在GetCell中--

下面是按钮事件处理程序的代码

void handler(Object sender, EventArgs args)
        {
            nint tag = btn.Tag;
var storyboard = UIStoryboard.FromName("Main", null);

            var controller = storyboard.InstantiateViewController("ProductDetailViewController") as ProductDetailViewController;
//  datatopass = yourlistofdata[tag]; Here I Will pass the data to the controller  -
            _controller.NavigationController.PushViewController(controller, true);


        }

您目前如何从ViewController1(产品)导航到ViewController2(产品详细信息)?@apineda如果您想查看,我添加了代码。请告诉我您对此有何看法您已经在这里有了viewcontroller的实例
var controller=storyboard.instanceeviewcontroller(“ProductDetailViewController”)作为ProductDetailViewController
这样您就可以将任何值分配给公共属性或创建一个公共方法,您可以在其中传入值并在ViewController中进行分配。@apineda是的,但我的问题是我不知道在哪里触发按钮事件来启动此操作,因为按钮在ProductCell类中,而我在我的表viewdatasource中无权访问它。我该怎么做?谢谢你的回答谢谢,就像我做的一样,只有一个问题,为什么你要取消订阅并直接在GetCell方法中订阅?GetCell方法称为多次。它可以重用以前创建的对象。所以,如果您的单元格1在顶部,单元格6在底部不可见,您可以向上滚动,当您使用“tableView.DequeueReusableCell”时会使用cell1,因为cell1不再可见。在cell1按钮上,您已经有了事件处理程序。因此,需要删除该事件,否则称为多次事件。想确认一下吗?注释掉用于删除处理程序的行,然后在tableview上向下滚动并单击“调试”按钮,以查看处理程序正在多次调用。
cell.yourbtn.Tag = indexPath.Row;
cell.getDetailButton.TouchUpInside -= handler;
cell.getDetailButton.TouchUpInside += handler;
void handler(Object sender, EventArgs args)
        {
            nint tag = btn.Tag;
var storyboard = UIStoryboard.FromName("Main", null);

            var controller = storyboard.InstantiateViewController("ProductDetailViewController") as ProductDetailViewController;
//  datatopass = yourlistofdata[tag]; Here I Will pass the data to the controller  -
            _controller.NavigationController.PushViewController(controller, true);


        }