Reputation: 820
As the titles says, I wonder if it is possible to create a windows programatically. Basically I want to create spawn a window at a random location on the screen when the user press a button. The problem I have is that if i create a view in runtime, it will disappear immediately after its created.
So is there any way to create windows, and then add them to an array and keeping them allocated?
Upvotes: 0
Views: 40
Reputation: 89549
The reason it's disappearing as soon as you're creating it is because you haven't added them to a (preferably mutable) array yet. As soon as your function exits, the window gets deallocated and it goes away.
Create a "@property
" or "ivar" for your mutable array (e.g. in your app delegate *
) and as soon as you create your window, add the window object to that array and your window will likely not disappear.
note: *
= app delegate is a terrible place to keep things, but for the purposes of getting you up to speed I'd recommend doing this to start with.
Upvotes: 1