配方中添加的Xamarin.IOS uibarbuttonite无效。没有错误,没有按钮
使用从选项卡式应用程序模板派生的Xamarin IOS应用程序。针对IOS 11+;在模拟器中测试12.1 我在其中一个UIView选项卡中添加了一个UINavigationBar,并尝试在该栏中添加一个保存和取消按钮 没有错误,没有乐趣,NavigationItem不为null,并显示正确的导航项。以下是大纲:配方中添加的Xamarin.IOS uibarbuttonite无效。没有错误,没有按钮,xamarin.ios,uinavigationbar,uibarbuttonitem,Xamarin.ios,Uinavigationbar,Uibarbuttonitem,使用从选项卡式应用程序模板派生的Xamarin IOS应用程序。针对IOS 11+;在模拟器中测试12.1 我在其中一个UIView选项卡中添加了一个UINavigationBar,并尝试在该栏中添加一个保存和取消按钮 没有错误,没有乐趣,NavigationItem不为null,并显示正确的导航项。以下是大纲: --UIViewController MyInfoController ----UIView InfoView ------UINavigationBar NavBar -------
--UIViewController MyInfoController
----UIView InfoView
------UINavigationBar NavBar
--------UINavigationItem [no name]
------UIView ContentView
------A bunch of constraints
----UITabBar
下面是相关的代码片段:
public partial class MyInfoController : UIViewController
{
protected MyInfoController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
this.NavigationItem.SetRightBarButtonItem(
new UIBarButtonItem(UIBarButtonSystemItem.Save, (sender, args) =>
{
// Handle Save Button Click here.
//Create Alert
var okAlertController = UIAlertController.Create("Click", "Right Button Clicked.", UIAlertControllerStyle.Alert);
//Add Action
okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
// Present Alert
PresentViewController(okAlertController, true, null);
}), true);
// Try another way...
var button = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (sender, e) =>
{
//Put Something here
});
button.SetTitleTextAttributes(new UITextAttributes()
{
TextColor = UIColor.White,
TextShadowColor = UIColor.Clear
}, UIControlState.Normal);
this.NavigationItem.SetLeftBarButtonItem(button, true);
// Create and add Views
没有错误消息问题。我没有看到任何错误,但我也没有看到工具栏按钮项
我错过了什么?(:-S)如果使用ios designer添加
UINavigationBar
和UINavigationItem
,最好为它们设置名称,如下所示
------UINavigationBar NavBar
--------UINavigationItem BarItem
因此,在控制器中,条形图将正常显示
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
this.BarItem.SetRightBarButtonItem(
new UIBarButtonItem(UIBarButtonSystemItem.Save, (sender, args) =>
{
// Handle Save Button Click here.
//Create Alert
var okAlertController = UIAlertController.Create("Click", "Right Button Clicked.", UIAlertControllerStyle.Alert);
//Add Action
okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
// Present Alert
PresentViewController(okAlertController, true, null);
}), true);
// Try another way...
var button = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (sender, e) =>
{
//Put Something here
});
button.SetTitleTextAttributes(new UITextAttributes()
{
TextColor = UIColor.Black,
TextShadowColor = UIColor.Clear
}, UIControlState.Normal);
this.BarItem.SetLeftBarButtonItem(button, true);
}
更多信息:
如果您使用
this.NavigationItem
,根控制器中常用的是UINavigationController,您是否使用UINavigationController
作为InfoController
的RootViewController
。根据提供的代码,我看不到。对不起,请原谅混淆的noob。MyInfoController是UIVewController,甚至没有rootviewcontroller作为成员。UIViewController是通过UIAbbarController调用的。您的UINavigationBar
和UINavigationItem
在哪里,您能解释代码吗谢谢!工作得很好!我真的很感激你对noob的耐心。