【发布时间】:2017-05-25 08:03:51
【问题描述】:
我是 iOS 开发新手,我搜索了我的问题,但大多数解决方案都是针对 Swift 3。我正在 Xamarin Native iOS 中开发我的应用程序。
我有一个包含数据列表的 UITableView。我需要做的就是当我点击一行时,该事件将通过 ViewController 打开一个新页面,该页面将显示所选数据的详细信息。
这是我在 PlayersListController.cs 文件中的 UITableView 代码:
public override void ViewDidLoad() {
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
// THIS data GOES TO "PlayersListTableSource" CLASSS
string[] data = new string[] {
"Player One",
"Player Two",
"Player Three",
"Player Four",
"Player Five"
};
UITableView myTable;
myTable = new UITableView
{
Frame = new CoreGraphics.CGRect(0, 30, View.Bounds.Width, View.Bounds.Height),
Source = new PlayersListTableSource(data)
};
View.AddSubview(myTable);
}
这是我的模型类 PlayersListTableSource.cspublic 类
PlayersListTableSource : UITableViewSource
{
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
// WHAT TO DO HERE…
new UIAlertView("Alert", "You touched: " + tableItems[indexPath.Row], null, "Ok", null).Show();
tableView.DeselectRow(indexPath, true);
// PlayerDetailController is my view controller I want to open on button click
// SOME THING LIKE THIS
PlayerDetailController PlayerDetailController = this.Storyboard.InstantiateViewController("PlayerDetailController") as PlayerDetailController;
this.NavigationController.PushViewController(PlayerDetailController, true);
}
}
【问题讨论】:
标签: ios uitableview xamarin.ios storyboard viewcontroller