0

I created a window based on NSWindowController It is called with...

view2Controller = [[View2Controller alloc] initWithWindowNibName:@"View2"];
[view2Controller showWindow:self];

That works great, and I have a functioning window.
Now I need to close it.

exit(0); // closes the entire application
close(0); // does is in the documentation, but it nothing

I found a suggestion to use..

[self dismissModalViewControllerAnimated:YES];

, but that seems to apply only to UI views, and generates an error.

How can I close the window that I have here?

Nils Munch
  • 8,805
  • 11
  • 51
  • 103
K17
  • 697
  • 3
  • 8
  • 26

3 Answers3

2

You seem to be confusing OS X and iOS programming. Both run objective-c, but only OS X is using initWithWindowNibName. From your tags, it seems like you are developing for iPhones.

Look up the tutorials on handling UIViews and UIViewControllers.

Nils Munch
  • 8,805
  • 11
  • 51
  • 103
  • Thank you. Yes, I am new to Apple programming and my terminology is sometimes off. But this is not an iPhone question. When I posted it, I specifically tagged it as XCode. – K17 May 30 '12 at 12:21
  • Hmm.. then someone have retagged it incorrectly... This should normally not occur, but then i would suggest using : makeKeyAndVisible on the new window. Do not call resignKeyWindow directly. – Nils Munch May 30 '12 at 12:32
  • I don't understand where makeKeyAndVisible would be used. It is kind of counter-intuitive to me. – K17 May 30 '12 at 12:43
  • Xcode is the IDE that can be used to make applications for iOS and OSX - so it needs to be tagged with OSX or iOS (or better Cocoa or Cocoa-touch) – mmmmmm May 30 '12 at 12:55
1

try [view2Controller removeFromSuperview];

In your case, I would use the View Based Application. The difference between window and view is that the window template does not create a view controller class and related user interface file (.xib). It just gives you a blank window. In iOS there can only be 1 window, but multiple views can be presented on that window.

The View based template does everything that the window based template does PLUS it creates a view controller class and that class's xib file. In addition, it adds that first view controller to your window. In iOS, when you want to show another view, you'll almost certainly want another view controller class. View controller classes can add additional views on top of themselves with ease.

Since the Window template gives you 0 to start with and the View template gives you 1 to start with and you'll eventually need 2 for your two views, it'll be less work for you to start with the View template.

hacker
  • 8,919
  • 12
  • 62
  • 108
0

if you're working with UIWindow you should take a look at this. but you're working with UIViewController, there are two solution:

1.) if your UIViewController is presenting as modalViewController

[myViewController dismissModalViewControllerAnimated:YES];

2.)else if your UIViewController navigated from other UIViewController or UIWindow you should try this:

[self.navigationController popViewControllerAnimated:YES];

if you're working with UIView, you should use: [myView removeFromSuperView];

Community
  • 1
  • 1
relower
  • 1,293
  • 1
  • 10
  • 20