-3

In my app I have one .xib file with three Windows. I'm not using Storyboard. To change the view between Windows when pressing a button, I used this code:

-(IBAction) SwitchView1 {

    [window setHidden:NO];
    [window1 setHidden:YES];
    [window2 setHidden:YES];
}

However I'm having some problems. Is there an alternative for my case?

Thank you in advance.

James Bedford
  • 28,702
  • 8
  • 57
  • 64
CrazySoftware
  • 133
  • 1
  • 2
  • 10

3 Answers3

2

Yes, window, window1 and window2 are instances of UIWindow

An iOS app has only one UIWindow. It is created at app launch and never changes. Do not do otherwise. It is wrong, foolish, and unnecessary. It is, quite simply, not how iOS programming is done.

See my answer here, for documentation citations:

https://stackoverflow.com/a/15909159/341994

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    you are correct in your answer, but I seriously think the guy meant `UIView`. `UIWindow` doesn't even respond to `setHidden` – luksfarris May 08 '13 at 19:08
  • 1
    @Luke Sure it does. UIWindow is a UIView subclass. UIView has `setHidden:`, therefore so does UIWindow; that is what it means to be a subclass. – matt May 08 '13 at 20:34
  • Oh my, you are correct again. But still.. – luksfarris May 09 '13 at 10:49
1

Are window, window1, and window2 instances of UIWindow? If so, you can't switch these windows (as there should only one UIWindow instance per app). You can switch views though (instances of UIView). I would also suggest looking at other ways that you can present views on iOS, as setting the hidden property of views is generally not the best approach.

James Bedford
  • 28,702
  • 8
  • 57
  • 64
  • Yes, window, window1 and window2 are instances of `UIWindow`. So if I want to change view without the hidden property of views must I insert more .xib files into my project? – CrazySoftware May 08 '13 at 18:54
  • There are many, many different ways to switch views. I honestly suggest you just read some beginners guides to iOS development. The Apple programming guides are very helpful. Those will get you going. – James Bedford May 08 '13 at 22:08
1

You should connect properly the button(IBAction) and the views (IBOutlets) ?

See this answer for more details on how to connect the interface with your code

Community
  • 1
  • 1
luksfarris
  • 1,313
  • 19
  • 38