gpt4 book ai didi

ios - 添加一个 uiview 来控制某些 uibuttons 无法正常工作 iphone monotouch

转载 作者:行者123 更新时间:2023-11-29 04:06:02 25 4
gpt4 key购买 nike

我使用此代码在 UIView 中添加 3 个 UIButtons,然后将它们添加到我的屏幕。

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 有关。当我调试该 View 的应用程序时,调试器在想要执行其值时会出现一些异常。我只能复制这个的头部:

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UIView enableInputClicksWh…

我不知道如何修复它。

最佳答案

我明白了。问题是我设置了 buttonsContainerView( 包含按钮的 View )40.但是设置按钮350的高度位置。当按钮的框架位于其父 View 的框架之外时,它不会响应您的触摸。

了解更多信息:UIButton inside UIView not clickable

关于ios - 添加一个 uiview 来控制某些 uibuttons 无法正常工作 iphone monotouch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15210341/

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