我试图在我的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);
}
}
}
答案 0 :(得分:0)
如何在将类按钮添加到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);
}