tags:

views:

52

answers:

1

I was trying out doing a manual instantiation of a view and all I get is a black screen.

Here's the core of my FinishedLoading

currentController = new ChoicesScreen(this.window.Handle);
window.AddSubview (currentController.View);
window.MakeKeyAndVisible();

note: CurrentController is a protected UIViewController currentController

ChoicesScreen is defined in IB, has the proper outlets, actions, etc. in other words its a valid view.

I tried the default constructor for ChoicesScreen and got the same thing. Obviously I'm missing something in how to get my own screen up.

+1  A: 

Driss,

You need to set the frame for the new view, to define where it'll show in the view:

currentController = new ChoicesScreen(this.window.Handle);
currentController.View.Frame = new System.Drawing.RectangleF(0, 0, 320, 480);
window.AddSubview (currentController.View);
window.MakeKeyAndVisible();
Eduardo Scoz
question for you, for each View that causes another View to be added on top, do I have to use the original window Handle and the original window.AddSubView or how do I stack them?
Driss Zouak
Not sure if I understood your question correctly, but you just need to add the top View to the window, only once (usually in the AppDelegate).After that, you can add as many Views (and controls, like buttons and labels) into that first view you created, using the AddSubview method.
Eduardo Scoz
But Views don't have a AddSubView method themselves, right? So is there a way that any view can access the window object so that they can AddSubView of another view that is to be presented? For example in Main.cs we have AddSubview(firstView), the user on firstView presses a button which is to bring up secondView, is there a way to access the window object to do window.AddSubview(secondView)?
Driss Zouak
UIViews do have AddSubview() method, so there's no need to go all the way to the window. You can find more info about it here: http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/addSubview:
Eduardo Scoz
Am I being dense or is it that in Monotouch UIViews have only an Add? Because in my code I'm only seeing Add (UIView) and no AddSubview(UIView). Same thing?
Driss Zouak
I am an idiot. I found it.
Driss Zouak