【问题标题】:Load. XIB in a class加载。 XIB在一个班级
【发布时间】:2012-06-20 17:12:18
【问题描述】:

我如何加载一个。 XIB 通过单击表格视图的行? 下面这个例子是一个类的一部分,因为我会提醒这个类的加载?

public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
    tableView.DeselectRow (indexPath, true);

    //this.PresentModalViewController(home,true);
}

【问题讨论】:

  • 你到底为什么要使用看起来像普通的 C 方法?使用 UITableViewController 中的 Objective-c 方法。
  • 他的帖子被标记为 MonoTouch - 那是 C#,而不是 Obj-C
  • 抱歉,我不知道你可以在不使用 Obj-C 的情况下为 iPhone 编程
  • 该类与其余代码分离,我不能使用 this.PresentModalViewController(home,true);

标签: c# iphone uitableview xamarin.ios nib


【解决方案1】:

你的问题和cmets中没有太多细节......

如果您使用override RowSelected 方法,那么您很可能从UITableViewSource 继承了一个新类型,对吗?如果是这样,那么您应该使其构造函数保留对UITableViewController 的引用,并使用此引用稍后调用PresentModalViewController

例如

public class MyTableViewSource : UITableViewSource {

    UITableViewController ctrl;

    public MyTableViewSource (UITableViewController c)
    {
        ctrl = c;
    }

    public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
    {
        tableView.DeselectRow (indexPath, true);
        var home = new UIViewController ("YouNibName", null); // default bundle
        ctrl.PresentModalViewController (home, true);
    }
}

注意:我使用了UIViewController,但您可能已经为您的 NIB 定义了一个类型。

【讨论】:

  • 错误:MonoTouch.UIKit.UITableView' 不包含 `PresentModalViewController' 的定义并且没有扩展方法
  • 我正在继承 UITableViewSource。
  • 同样的模式适用于UITableViewSource,你应该传递UITableViewController(不是视图本身)。我将更新代码示例...
猜你喜欢
  • 1970-01-01
  • 2017-11-05
  • 1970-01-01
  • 2016-11-25
  • 2018-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-16
相关资源
最近更新 更多