c# - 如何通过单击 Xamarin 4 中的 TableView 单元格打开 TableView

标签 c# ios uitableview xamarin

SCREEN SHOT我是 Xamarin 和 C# 的新手,

我想知道如何通过在 Xamarin 中按下表格 View 单元格来打开新的表格 View Controller ?现在,我的应用程序会打开我的表格 View 并对其进行编程,因此当按下该表格 View 中的单元格时,会打开一个弹出窗口,显示“已选择行...等等。”

谢谢

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 上有一个食谱 website .这显示了如何处理 tableview 点击事件。要展示新的 View Controller ,您需要做类似的事情

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

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

Here是另一个资源。它是一个由不同 friend 组成的表格 View ,当用户选择其中一行时,它将转入另一个 View ,其中包含有关所选行的信息。

关于c# - 如何通过单击 Xamarin 4 中的 TableView 单元格打开 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45086289/

相关文章:

c# - Linq 获取按最快日期排序的第一行,其中 B 列不是 "Expired"或 "Cancelled"

c# - ServiceStack:如何从我的 AppHost 中的 ServiceExceptionHandler 中获取 IHttpRequest 对象?

ios - 在当前位置和单独位置 mkmapview 上放置地标

ios - 自调整单元格对我不起作用

ios - 在包含 UITableView subview 的自定义 UIViewController 中检测多点触控

ios - tableview 静态单元格动态页脚

c# - 发生异常 .. 关键字 'Table' 附近的语法不正确

c# - IsLittleEndian 字段报错,但一定是Little-Endian?

ios - 如何从单元格中另一个项目的手势获取单元格引用

iphone - 为什么 SimpleEKDemo 代码中存在内存泄漏?