UITabBarController에서 파생 된 클래스에서 작업했습니다. 가장 기본적인 수준에서, 내가하려는 것은 BackgroundColor 속성과 다른 공용 속성을 추가하는 것입니다.이 속성은 TabBarController를 구성 할 때 AppDelegate에서 인스턴스화 할 수 있습니다.MonoTouch의 사용자 정의 TabBarController에서 ViewDidLoad의 공용 속성은 항상 null입니다.
내가 만난 문제는 ViewDidLoad가 호출 될 때 모든 public 속성이 null이되거나, 생성자와 [Register] 특성을 추가 할 수 있고 null이 아닌 속성을 갖게된다는 것입니다. , ViewControllers 속성 (모든 탭이 들어 있음)은 설명 할 수 없게 null이됩니다 (ViewDidLoad에서 설정 한 경우에도 마찬가지입니다).
분명히, 나는 두 가지 사실이 모두 필요하며 나는 뭔가 구체적인 것을 놓치고 있습니다. 여기
내가 AppDelegate에 명시 적으로 설정 한 경우에도 항상 널의 backgroundColor 결과 코드의 버전입니다 : 여기public class TabBarController : UITabBarController
{
public UIColor BackgroundColor { get; set; }
public override ViewDidLoad()
{
base.ViewDidLoad();
if(BackgroundColor != null) // Always null, even when set explicitly
{
var frame = new RectangleF(0.0f, 0.0f, this.View.Bounds.Size.Width, 46);
UIView myTabView = new UIView(frame);
myTabView.BackgroundColor = BackgroundColor;
myTabView.Alpha = 0.5f;
this.TabBar.InsertSubview(myTabView, 0);
}
// Add tabs here, which show up correctly (on default background color)
ViewControllers = new UIViewController[] { one, two, three, etc };
}
}
정확한 배경 색상을 보여줍니다 편집 코드 (재산이다 NOT NULL)하지만, 그것이 단지의 viewDidLoad에 설정되어있는 경우에도 ViewControllers 속성이 null하지만 아무것도 할 수 있도록 거부 :
는[Register("TabBarController")]
public class TabBarController : UITabBarController
{
public UIColor BackgroundColor { get; set; }
// Added a binding constructor
[Export("init")]
public TabBarController() : base(NSObjectFlag.Empty)
{
}
public override ViewDidLoad()
{
base.ViewDidLoad();
if(BackgroundColor != null) // Hey, this works now!
{
var frame = new RectangleF(0.0f, 0.0f, this.View.Bounds.Size.Width, 46);
UIView myTabView = new UIView(frame);
myTabView.BackgroundColor = BackgroundColor;
myTabView.Alpha = 0.5f;
this.TabBar.InsertSubview(myTabView, 0);
}
// Tabs disappear, ViewControllers is always null
ViewControllers = new UIViewController[] { one, two, three, etc };
if(ViewControllers == null)
{
Console.WriteLine("Not bro");
}
}
}
이것은 분명히 내가 명시 적으로하지 않고 모든 요소를 추가해야하는 경우 일부 사용자 지정 컨트롤을 작성하는 내 능력을 방지 할 수 있습니다 가능하다 o 런타임에 공용 속성에 액세스합니다. 아무도 내가 잘못 가고 있는지 알 수 있습니까?
"public override ViewDidLoad()"는 컴파일되지 않습니다. – poupou