来自UITableview的Xamarin iOS显示细节

时间:2017-01-28 11:44:29

标签: uitableview xamarin xamarin.ios

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

Exemple

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

这是我的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;
        }

这是我的产品定制单元格:

public partial class ProductCell : UITableViewCell
    {
        public static readonly NSString Key = new NSString("ProductCell");

        public ProductCell(IntPtr handle) : base(handle)
        {
        }

        public ProductCell(NSString cellId)
        {
        }

        public void UpdateCell(string imageName, nint tag)
        {
            this.ProductImage.Image = UIImage.FromBundle(imageName);
            this.MoreBtn.Tag = tag;
        }
}

编辑: 这是我的导航代码,我将它放在动作按钮方法中。但是现在我不知道在哪里创建这个方法:

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

1 个答案:

答案 0 :(得分:2)

在GetCell中 -

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


        }