2012-06-20 92 views
1

如何加载a。 XIB通过点击表格视图的行? 下面这个例子是一个类的一部分,因为我fario警告这个类的加载?加载。 XIB in a class

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

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

为什么在地球上你用什么看起来像普通的C方法?在UITableViewController中使用objective-c方法。 –

+0

他的帖子被标记为MonoTouch - 这是C#,而不是Obj-C – Jason

+0

对不起,我不知道你可以编程为iPhone而不使用Obj-C –

回答

0

这里没有很多细节在你的问题和评论...

如果overrideRowSelected方法,那么你很可能从UITableViewSource权继承了新的类型?如果是这样,那么你应该让它的构造函数保留对UITableViewController的引用,并在稍后使用此引用来呼叫PresentModalViewController

E.g.

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定义的类型。

+0

错误:MonoTouch.UIKit.UITableView'不包含'PresentModalViewController'的定义并且没有扩展方法 – Lima

+0

**我继承了UITableViewSource。** – Lima

+0

相同的模式适用于'UITableViewSource',您应该通过'UITableViewController' (而不是视图本身)。我会更新代码示例... – poupou