Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Adding a button to UINavigationController.NavigationItem

$
0
0

Hi,

I built that very simple UINavigationController subclass:

public class TweakedNavigationController : UINavigationController
{
    public TweakedNavigationController(UIViewController rootViewController) : base(rootViewController)
    {
    }

    public override void ViewDidLoad() // tried right into constructor, viewdidload and viewdidappear
    {
        base.ViewDidLoad();
        // creating simple button
        UIBarButtonItem barButtonItem = new UIBarButtonItem(
            UIImage.FromBundle("first"),
            UIBarButtonItemStyle.Plain,
            (sender,args) => {
                Console.Out.WriteLine("Oh sheet!");
            }
        );

        // make sure we see it
        barButtonItem.TintColor = UIColor.Black;

        // add text
        barButtonItem.Title = "Login";

        // add to navigationitem
        NavigationItem.SetRightBarButtonItem(barButtonItem, false);
    }
}

This class is instantiated from a UIViewController like this:

public override void ViewDidLoad()
{
    base.ViewDidLoad();

    UIRefreshControl refreshControl = new UIRefreshControl();

    refreshControl.ValueChanged += (object sender, EventArgs e) => {
        GetPinsAndShowLoading();
    };

    TableViewController.RefreshControl = refreshControl;

    TableViewController.RefreshControl.BeginRefreshing();

    // creating instance of navigationcontroller
    TweakedNavigationController = new TweakedNavigationController(TableViewController);

    // add subview to view
    Add(NavigationController.View);

    GetPinsAndShowLoading();
}

I tried to run it from multiple places but I cannot wrap my head around why that button never get shown! Any ideas?

Thanks a lot and have a nice day


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>