views:

1385

answers:

4

I need to add a view to window on iPhone, so i tried to do this: [[UIApplication sharedApplication] windows], but it seams that the array contains only one window.

Can anyone tell me what i'm not doing write/what i need to do?

+2  A: 

try

[[UIApplication sharedApplication] keyWindow];

if you want to find your app's window.

Morion
It does not work. I tried.
mxg
If [[UIApplication sharedApplication] windows] retuns nothing, then [[UIApplication sharedApplication] keyWindow] will throw an exception
mxg
hmmm.... it is very strange. where in your app do you call this method?
Morion
@Morion, in a UITableViewController, after MPMoviePlayerController has started playing. Apple's example works well.
mxg
+2  A: 

Your AppDelegate class will hold the window (as a property). You only get one window per application. In most cases you should only add views directly to the window from the AppDelegate -- for normal subview management, use viewControllers.

Ian Henry
MPMoviePlayerController seams to start into a different window, but I need it to add an overlay on the MoviePlayer window.
mxg
Ah, I see. I found this post about it, which claims to be able to do it on 3.0: http://amromousa.com/2009/03/22/overlay-uiview-on-mpmovieplayercontroller/ but, the usual warning -- Apple might get mad.
Ian Henry
A: 

You could do something like this.

UIView *controllersView = [myViewController view];

[window addSubview:controllersView];
Johan Wikström
It is on the video window. So i don't have access to view.
mxg
And where did that variable "window" come from?
nash
A: 

Well, I found the problem. Actually conditions where not set correct, [[UIApplication sharedApplication] windows] returned only one window. Still, [[UIApplication sharedApplication] keyWindow] throw an exception.

It was because When MPVideoPlayerController starts playing, it starts creating a new window, but, probably does not finish this job immediately. It is created ALMOST immediately, but not immediately.

mxg