gpt4 book ai didi

c# - 如何在 DialogViewController 上将背景设置为透明

转载 作者:行者123 更新时间:2023-11-29 13:38:03 24 4
gpt4 key购买 nike

当我将 MonoTouch.Dialog 背景色设置为 uiclear(transparent) 时,它抛出异常,为什么?以及如何将其设置为透明。

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object MyDialogViewController.LoadView () [0x00016] in MyDialogViewController.cs: ParentViewController.View.BackgroundColor = UIColor.Clear

public class MyDialogViewController: DialogViewController
{
public MyDialogViewController (RootElement root) : base (root)
{
}

public override void LoadView()
{
base.LoadView ();
this.TableView.BackgroundColor = UIColor.Clear;
ParentViewController.View.BackgroundColor = UIColor.Clear;

}
}


public void xxxxx(){
var menu = new RootElement(""){
new Section ("Demo"){
new EntryElement("Name", "",""),
},
};

var menuDVC = new MyDialogViewController (menu) {
Autorotate = true
};



this.View.AddSubview(menuDVC.View);
}

最佳答案

NullReferenceException 很可能 发生是因为 ParentViewControllernull

根据您的 MyDialogViewController 的显示方式,这可能是由于使用了错误的属性和最近的 iOS5,change :

Prior to iOS 5.0, if a view did not have a parent view controller and was being presented, the presenting view controller would be returned. On iOS 5, this behavior no longer occurs. Instead, use the presentingViewController property to access the presenting view controller.

但是,如果 MyDialogViewController 是窗口的 RootViewController,那么这些属性通常为 null。在这种情况下,只需在 TableView 上使用 UIColor.Clear 即可获得黑色背景(我那里什么都没有),因此对于 MT.D 部分来说应该足够了。如果您有一个父级,那么您可以在显示您的 MyDialogViewController 之前尝试将其背景颜色设置为清除(如果需要)。

关于c# - 如何在 DialogViewController 上将背景设置为透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9977427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com