0

このコードを使用して、に3UIButtonsUIView追加してから、画面に追加しています。

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 );

アプリケーションを実行するとき。ボタンが正しい場所に追加されました。Textただし、には何も含まれていませんTitleLable。このアイテムを設定している間。また、それらはいくつかの画像のように見えるので、私はそれらをクリックしてそれらと対話することができません。

私は彼らの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…

修正方法がわかりません。

4

3 に答える 3

1

わかった。問題は、buttonsContainerView(ボタンを含むビュー)40の高さを設定しているのに、ボタン350の高さの位置を設定していることです。ボタンのフレームが親ビューのフレームの外側にあると、タッチに反応しません。

詳細:UIView内のUIButtonはクリックできません

于 2013-03-05T08:48:59.903 に答える
0

SetTitle();を使用する必要があります。それを機能させるためのUIButtonの機能。そうしないと、TitleLabelは設定されません。

button.SetTitle("MyTitle",UIControlState.Normal);
于 2013-03-04T20:40:51.527 に答える
0

これはおそらくコメントのはずですが、まだコメントできません。私はあなたの実装が奇妙だと思い、それがARCの誤動作を引き起こすと思う傾向があります(リリースコードがないのでARCを想定しています)。このループの代わりに3つのUIButtonを作成してから、それらすべてをUIViewに追加してみませんか?

于 2013-03-04T20:26:04.490 に答える