Xamarin.ios monotouch中的UITableView导航
我正在使用mono develop 3.1.1构建一个IOS应用程序。我从对导航控制器的引用中收到一个对象引用错误(请参见>>>),我没有正确声明该错误 我的问题是,声明和实例化控制器的最佳方式是什么,这样我就可以从选择表单元格的角度显示另一个视图 有人能帮我正确的语法吗Xamarin.ios monotouch中的UITableView导航,xamarin.ios,monodevelop,Xamarin.ios,Monodevelop,我正在使用mono develop 3.1.1构建一个IOS应用程序。我从对导航控制器的引用中收到一个对象引用错误(请参见>>>),我没有正确声明该错误 我的问题是,声明和实例化控制器的最佳方式是什么,这样我就可以从选择表单元格的角度显示另一个视图 有人能帮我正确的语法吗 public class TableHelper : UITableViewSource { protected string[] tableItems; protected string cellIdenti
public class TableHelper : UITableViewSource {
protected string[] tableItems;
protected string cellIdentifier = "TableCell";
public TableHelper (string[] items)
{
tableItems = items;
}
public override int RowsInSection (UITableView tableview, int section)
{
return tableItems.Length;
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
switch (tableItems[indexPath.Row])
{
case "one":
var DetailViewController = new SupportContactsDetailsScreen ();
UINavigationController controller = new UINavigationController();
// Pass the selected object to the new view controller.
>>>controller.NavigationController.PushViewController(DetailViewController, true);
break;
default:
//Console.WriteLine("Default case");
break;
}
}
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
cell.TextLabel.Text = tableItems[indexPath.Row];
return cell;
}
}
我通常这样做的方式是为特定的视图集保留对主UIViewController(保存UITableView的视图控制器)的引用,并通过NavigationController属性访问该导航控制器。(Xamarin在下面链接的代码示例中采用的另一种技术是直接将UINavigationController传入。) 因此,我将通过添加以下内容来更改您的类:
UIViewController parentViewController;
public TableHelper(string[] items, UIViewController vc)
{
tableItems = items;
parentViewController vc;
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
switch (tableItems[indexPath.Row])
{
case "one":
var DetailViewController = new SupportContactsDetailsScreen ();
UINavigationController controller = new UINavigationController();
// Pass the selected object to the new view controller.
parentViewController.NavigationController.PushViewController(DetailViewController, true);
break;
default:
//Console.WriteLine("Default case");
break;
}
}
Xamarin在他们的docs网站上和他们的网站上都有一个进一步讨论这个问题的网站。另一个重要注意事项是视图控制器的类型(常规UIViewController、UITableViewController等)。嗨,皮尔斯,谢谢你提供的信息。我确实从xamarin文档网站上得到了上面的示例。我正在努力解决的问题是,当我调用初始化类时,如何传递控制器?like table.Source=新的TableHelper(tableItems,