Fal*_*ler 0 tableview xamarin.ios ios xamarin
我正在开发一个与Xamarin相当简单的应用程序,但我坚持一件事:我在UIViewController中创建了一个tableView.单元格渲染在外部类中完成:TableSource.cs.UITableViewSource的子类.要处理行,请单击我确实覆盖选中的行:
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
new UIAlertView("Row Selected", tableItems[indexPath.Row], null, "OK", null).Show();
tableView.DeselectRow (indexPath, true); // iOS convention is to remove the highlight
//Push another ViewController on top:
UINavigationController test = new UINavigationController ();
test.PushViewController (new UIViewController (),true);
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,魅力的作用.但是当我尝试在顶部推送另一个ViewController时,为了显示有关该行的详细数据,没有任何反应,我没有收到任何错误或异常消息.我也尝试使用Nav的自定义类.控制器和视图控制器,它不会改变任何东西.
你不能只是创建一个新的UINavigationController并像这样使用它.相反,您需要在创建TVC时将UITableViewController包装在UINavigationController中 - 然后在RowSelected中,您可以使用现有的NavigationController在堆栈上推送新的ViewController.
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
new UIAlertView("Row Selected", tableItems[indexPath.Row], null, "OK", null).Show();
tableView.DeselectRow (indexPath, true); // iOS convention is to remove the highlight
// parent is a reference to the UITableViewController - you will need to pass this into
// your TableSource class. Every ViewController has a NavigationController property - if
// the VC is contained in a Nav controller this property will be set.
parent.NavigationController.PushViewController(new UIViewController(), true);
}
Run Code Online (Sandbox Code Playgroud)
在创建TableSource时,传入对TableViewController的引用,以便源的RowSelected方法可以访问NavigationController.
// in your TableViewController, when you assign the Source property
TableView.Source = new MyTableSource(this);
// in the MyTableSource class
TableViewController parent;
public MyTableSource(TableViewController parent) {
this.parent = parent;
}
Run Code Online (Sandbox Code Playgroud)
现在,在您的RowSelected方法中,您可以访问 parent.NavigationController
归档时间: |
|
查看次数: |
4162 次 |
最近记录: |