2011-11-29 90 views
0

如何從我的BasisViewController中的AccessoryButtonTapped按鈕打開一個新窗口。現在我有這個打開,但問題是我無法找到的NavigationController,因爲我是固有的UITableViewSource。MonoTouch無法從AccessoryButtonTapped打開新窗口

Opskrift ops = new Opskrift(item.ImageName, item.Name, item.optionTxt, item.SubHeading) 
this.NavigationController.PushViewController(this.opskrift, true); 

如果我使用ops.NavigationController.PushViewController(this.opskrift, true);

我得到一個對象引用未設置到對象異常的實例。

回答

3

將其通過它的構造給你UITableViewSource繼承類訪問你的控制器:

public class MyTableSource : UITableViewSource 
{ 

    private BasisViewController controller; 
    public MyTableSource(BasisViewController parentController) 
    { 
     this.controller = parentController; 
    } 

    //use like this in a method: 
    //this.controller.NavigationController.PushViewController(opskrift, true); 
} 

,因爲它不是一個導航控制器的堆棧的一部分,當你初始化(你Opfskrift控制器的NavigationController屬性返回null =尚未在導航控制器中「推」)。當然,BasisViewController也必須屬於NavigationController屬性的導航控制器,以包含除null以外的內容。

+0

我得到一個錯誤:\t Example_CustomUITableViewCells.MyTableSource「不實現繼承的抽象成員'MonoTouch.UIKit.UITableViewSource.RowsInSection(MonoTouch.UIKit.UITableView,INT)」 Example_CustomUITableViewCells.MyTableSource」不實現繼承的抽象成員'MonoTouch.UIKit.UITableViewSource.GetCell(MonoTouch.UIKit.UITableView,MonoTouch.Foundation.NSIndexPath)' 我應該實現它們並返回一些空值。 – mortenstarck

+0

這兩個方法是必需的,以便您的表視圖可以創建要顯示的項目列表。如果您從GetCell返回null,並從RowsInSection返回0,則表格視圖中不會顯示任何項目。 –