Volker Mauel
Volker Mauel

Reputation: 522

MonoTouch: button not visible

so i recently decided to join iOS development,mainly because i love to extend my knowledge across multiply platforms, and as i already know java and wrote an android app, iOS was the next step.

So my question would be this: In a table i use a custom tablesource to react to a click on a row with a new view being loaded. Now in that view,i want to add a back button to return to the previous view.

   PointF locationOne = new PointF (5, 5);
    PointF locationTwo = new PointF (5, 100);
    SizeF size = new SizeF (120, 40);

    RectangleF tView = new RectangleF (locationOne, size);
    RectangleF tView2 = new RectangleF (locationTwo, size);
        UILabel l1 = new UILabel(){Text = "LOOL",Frame=tView};

        UIButton backbutton = new UIButton(){
            Frame=tView2
        };
        backbutton.Frame = tView2;
        backbutton.TitleLabel.Text = "Zurueck";
        backbutton.Hidden = false;

        UIView previousview = viewController.View;
        backbutton.TouchDown += (sender, e) => { 
            viewController.View = previousview;
        };

        UIView v = new UIView();
        v.AddSubview(l1);
        v.AddSubview (backbutton);


        viewController.View = v;

this would be my code right now. the label is being displayed, the button isn't. is there something i'm missing?

Thanks already :)

Upvotes: 1

Views: 741

Answers (1)

Roland Mai
Roland Mai

Reputation: 31077

The UIView v has no frame. You need to set it to the frame of the parent controller (maybe v.Frame = viewController.View.Frame;). Then, swap out the view of viewcontroller.

Edit:

The initialization of UIButton is not right. Here's how to create a regular button:

PointF locationOne = new PointF (5, 5);
PointF locationTwo = new PointF (5, 100);
SizeF size = new SizeF (120, 40);

RectangleF tView = new RectangleF (locationOne, size);
RectangleF tView2 = new RectangleF (locationTwo, size);
UILabel l1 = new UILabel (){Text = "LOOL",Frame=tView};

UIButton backbutton = UIButton.FromType(UIButtonType.RoundedRect);
backbutton.Frame = tView2;
backbutton.SetTitle("Zurueck", UIControlState.Normal);

UIView previousview = viewController.View;
backbutton.TouchUpInside += (sender, e) => { 
    viewController.View = previousview;
};

UIView v = new UIView ();
v.BackgroundColor = UIColor.White;
v.AddSubview (l1);
v.AddSubview (backbutton);
viewController.View = v;

Upvotes: 1

Related Questions