我使用此代碼在UIView
中添加3 UIButtons
,然後將它們添加到我的屏幕。添加一個uiview,提到一些uibuttons無法正常工作iphone monotouch
UIView buttonsContainerView = new UIView (new Rectangle (0,0,(int) this.View .Frame .Width ,40));
UIButton b;
for(int i=0;i<3;i++){
b= new RltTabBarButton();
b.ImageEdgeInsets = new UIEdgeInsets (5,5,5,100);
if(i==0){
b.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal);
b.TitleLabel .Text = "Details";
b.Frame = new RectangleF (0,350,108,40);
b.Enabled =true ;
}else if(i==1){
b.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal);
b.TitleLabel .Text = "Map";
b.Frame = new RectangleF (110,350,100,40);
b.Enabled =true ;
}else if(i==2){
b.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal);
b.TitleLabel .Text = "Agent";
b.Frame = new RectangleF (212,350,108,40);
b.Enabled =true ;
}
buttonsContainerView .AddSubview (b);
}
this.View .AddSubview (buttonsContainerView);
當我運行我的應用程序。按鈕添加在他們正確的地方。但他們的TitleLable
不包括Text
。當我設置這個項目。他們看起來像一些圖像,所以我不能點擊它們並與它們進行交互。
我設置了他們的Enabled
字段true
但沒有任何更改。
編輯: 根據答案我改變了我的代碼如下:
UIView buttonsContainerView = new UIView (new Rectangle (0,0,(int) this.View .Frame .Width ,40));
UIButton DetailsButton= new UIButton (UIButtonType.RoundedRect );
DetailsButton.ImageEdgeInsets = new UIEdgeInsets (5,5,5,100);
DetailsButton.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal);
DetailsButton.SetTitle ("Details",UIControlState.Normal);
DetailsButton.Frame = new RectangleF (0,350,108,40);
buttonsContainerView .AddSubview (DetailsButton);
UIButton MapButton= new UIButton (UIButtonType.RoundedRect);
MapButton.ImageEdgeInsets = new UIEdgeInsets (5,5,5,100);
MapButton.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal);
MapButton.SetTitle ("Map",UIControlState.Normal);
MapButton.Frame = new RectangleF (110,350,100,40);
buttonsContainerView .AddSubview (MapButton);
UIButton AgentButton= new UIButton (UIButtonType.RoundedRect );
AgentButton.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal);
AgentButton.SetTitle ("Agent",UIControlState.Normal);
AgentButton.Frame = new RectangleF (212,350,108,40);
buttonsContainerView .AddSubview (AgentButton);
this.View .AddSubview (buttonsContainerView);
但沒有任何變化。我們無法點擊按鈕。他們看起來像圖像。我認爲它與buttonsContainerView
和EnableInputClicksWhenVisible
有關。當我調試應用程序這個視圖時,調試器在想要執行其值時有一些豁免。 我能只是頭複製這樣的:
MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[UIView enableInputClicksWh…
我不知道如何解決它。
感謝您的回覆。我是一個新的monotouch和iphone。我不知道什麼是ARC。我在此之前在不同的按鈕中實現它們。這樣,他們可以點擊,但他們的文字也不會出現。 :( – 2013-03-04 20:32:00