簡體   English   中英

無法在TabController內的NavigatioNController中的Xamarin iOS中添加導航項

[英]Can't Add Navigation Item in Xamarin iOS in NavigatioNController inside TabController

我正在嘗試向我的Navbar添加一個NavigationItem,當我在我的設備上部署它時它不會顯示。

我認為它類似於xamarin網站上的教程。

有任何想法嗎?

這是我的代碼:

using System;
using UIKit;

namespace myNameSpace
{
    public class LinksPageController : UINavigationController
    {
        public LinksPageController ()
        {
            NavigationBar.BarTintColor = UIColor.FromRGB (183, 28, 28);
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            this.NavigationItem.SetRightBarButtonItem(
                new UIBarButtonItem(UIBarButtonSystemItem.Action, (sender,args) => {
                    UIAlertView alert = new UIAlertView("Add link!", "Enter the ID of the person you want to be linked with:", null, "Cancel", "OK");
                    alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
                    alert.Show ();
                })
                , true);
        }

        public override void ViewWillAppear (bool animated)
        {
            base.ViewWillAppear (animated);
        }
    }
}

如何在將類按鈕添加到navBar之前實例化它? 可能是你正在丟失實例指針.. ??

UIBarButtonItem * newButton;
public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        newButton =  new UIBarButtonItem(UIBarButtonSystemItem.Action, (sender,args) => {
                UIAlertView alert = new UIAlertView("Add link!", "Enter the ID of the person you want to be linked with:", null, "Cancel", "OK");
                alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
                alert.Show ();
            })

        this.NavigationItem.SetRightBarButtonItem(newButton, true);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM