-1

I am trying to create a view class to work with the flyout navigation component. As of yet, I have not found a way to create a view and add subview's to itself. Here is a sample view class that I have created--note, I am not using a XIB file because I would like to avoid XCode--it has been going in and out of sync constantly. This is simply a normal C# file that inherits UIView and attempts to create a view. How do I add subviews to it?

using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using FlyoutNavigation;
using MonoTouch.Dialog;

namespace Flyout
{
public class MessagesView : UIView
{
    public MessagesView ()
    {
        var field = new UITextField (new RectangleF(10f, 10f, 300f, 40f));
        field.Placeholder = "Test";
        field.BorderStyle = UITextBorderStyle.RoundedRect;
  // does not work  MessagesView.addSubview(field);
        var field2 = new UITextField (new RectangleF(10f, 60f, 300f, 40f));
        field2.Placeholder = "Test2";
        field2.BorderStyle = UITextBorderStyle.RoundedRect;
    }
}

}

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
Yahiko Kikikoto
  • 688
  • 3
  • 12
  • 23
  • 1
    "does not work" - what does not work when you try AddSubview? Do you get an error? Or is the field just not visible on the view? – Jason Jun 12 '13 at 19:43
  • have you tried this.AddSubview() instead of MessagesView.AddSubview()? MessagesView is a class, not an instance. And you should probably put that logic in your ViewDidAppear() method, not the constructor. – Jason Jun 12 '13 at 19:56

1 Answers1

0

UIView has an AddSubview() method.

[MonoTouch.Foundation.Export("addSubview:")]
public virtual void AddSubview (UIView view)
Jason
  • 86,222
  • 15
  • 131
  • 146