C# 如何通过单击Xamarin4中的表视图单元格打开表视图

C# 如何通过单击Xamarin4中的表视图单元格打开表视图,c#,ios,uitableview,xamarin,C#,Ios,Uitableview,Xamarin,我对Xamarin和C都是新手 我想知道如何通过按下Xamarin中的表视图单元格来打开新的表视图控制器?现在我的应用程序打开了我的表格视图,它被编程了,所以当按下表格视图中的一个单元格时,会弹出一个窗口,显示“行已选定…”。。。等等 多谢各位 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Foundation; using UIKit; namespac

我对Xamarin和C都是新手

我想知道如何通过按下Xamarin中的表视图单元格来打开新的表视图控制器?现在我的应用程序打开了我的表格视图,它被编程了,所以当按下表格视图中的一个单元格时,会弹出一个窗口,显示“行已选定…”。。。等等

多谢各位

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Foundation;
using UIKit;

namespace App2

{
    public class TableSource : UITableViewSource
    {
        string[] TableItems;
        string CellIdentifier = "TableCell";

        public TableSource(string[] items)
        {
            TableItems = items;
        }

        public override nint RowsInSection(UITableView tableview, nint section)
        {
            return TableItems.Length;
        }

        public static string SelectedRow;

        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            new UIAlertView("Row Selected", TableItems[indexPath.Row], null, "OK").Show();
#pragma warning restore CS0618 // Type or member is obsolete

            SelectedRow = TableItems[indexPath.Row];
        }


        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
            string item = TableItems[indexPath.Row];

            //---- if there are no cells to reuse, create a new one
            if (cell == null)
            { cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier); }

            cell.TextLabel.Text = item;

            return cell;
        }
    }
}

Xamarin上有一个配方。这显示了如何处理tableview点击事件。要演示新的viewcontroller,您可以执行类似的操作

public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{

 ViewController vc = new ViewController();
 PresentViewController(vc, true, null);
}

这是另一种资源。这是一个由不同朋友填充的tableview,当用户选择其中一行时,它将进入另一个视图,其中包含所选行的信息。

如果您向我们展示迄今为止获得的代码,我们可以为您提供更多帮助。它使我们更容易根据您自己的代码提供更准确的示例,而不是指南中的示例。因此,您希望在选择tableview项目后显示新视图,而不是显示弹出窗口?正确。该显示仅用于测试目的;把代码放在你的问题中。你以什么方式使用所选项目?这是针对Xamarin.Forms的,他的屏幕截图看起来像一个原生的Xamarin.ios项目。是的,它只是一个单视图ios应用程序编辑,让我知道这是否有帮助@R。Drake@R.Drake对不起,我现在不能在工作中测试它。我用我的一个项目中的更多资源编辑了我的答案。这是一个朋友列表,当您单击tableview单元格时,它将进入另一个视图并显示该朋友的信息。@Grady如果有机会,您可以看看它是否有效。