1

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?

RedBlueThing
  • 42,006
  • 17
  • 96
  • 122
mxg
  • 20,946
  • 12
  • 59
  • 80

4 Answers4

3

try

[[UIApplication sharedApplication] keyWindow];

if you want to find your app's window.

Morion
  • 10,495
  • 1
  • 24
  • 33
  • If [[UIApplication sharedApplication] windows] retuns nothing, then [[UIApplication sharedApplication] keyWindow] will throw an exception – mxg Dec 10 '09 at 08:54
  • @Morion, in a UITableViewController, after MPMoviePlayerController has started playing. Apple's example works well. – mxg Dec 10 '09 at 11:04
2

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
  • 22,255
  • 4
  • 50
  • 61
  • MPMoviePlayerController seams to start into a different window, but I need it to add an overlay on the MoviePlayer window. – mxg Dec 10 '09 at 11:23
  • 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 Dec 10 '09 at 14:16
1

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
  • 20,946
  • 12
  • 59
  • 80
0

You could do something like this.

UIView *controllersView = [myViewController view];

[window addSubview:controllersView];
Johan Wikström
  • 921
  • 8
  • 18