简体   繁体   中英

MonoTouch can't open new window from AccessoryButtonTapped

How do I open an new window from AccessoryButtonTapped button from my BasisViewController. Right now I have this for open, but the problem is the NavigationController which I can't find because I'm inherent the UITableViewSource.

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

If I use ops.NavigationController.PushViewController(this.opskrift, true);

I get an Object reference not set to an instance of an object exception.

Give your UITableViewSource inherited class access to your controller by passing it through its constructor:

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);
}

Your Opfskrift controller's NavigationController property returns null because it is not part of a navigation controller's stack when you initialize it (=hasn't been "pushed" in a navigation controller). Of course, BasisViewController must also belong to a navigation controller for its NavigationController property to contain something other than null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM