K17
K17

Reputation: 697

How to close a view -- Xcode

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?

Upvotes: 0

Views: 6116

Answers (3)

hacker
hacker

Reputation: 8947

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.

Upvotes: 1

relower
relower

Reputation: 1313

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];

Upvotes: 0

Nils Munch
Nils Munch

Reputation: 8845

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.

Upvotes: 2

Related Questions