gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 17:49:46 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com