• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unable to Terminate Application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unable to Terminate Application


  • Subject: Re: Unable to Terminate Application
  • From: "Frederick C. Lee" <email@hidden>
  • Date: Tue, 30 Mar 2004 14:46:55 -0800

Essentially I have a main.m that launches the NSApp.
I have 'myController.m' that interfaces with a NSWindow that responds to a NSTextField object which is an input for the key to NSDictionary that returns a value into the second NSTextField for display. When the user enters a null value, I want the NSApp to terminate gracefully.


Inside 'myController.m' within the IBAction menthod received from 'Enter', I test for an empty string.
If true, then TERMINATE the program.


- (IBAction)Enter:(id)sender {
NSString * myString;
myString = [AreaCode stringValue];
if ([myString length] == 0) {
NSLog(@"No data input.");
[[NSApplication sharedApplication] terminate]; <--- HERE IS WHERE I'M CONFUSED. IT WAS: [self dealloc], but replaced it.
} else {
myString = [myAreaCode LookUp:[AreaCode stringValue]];
}


------

I get a compiler error if I put in the terminate statement: 'NSApplication may not respond to 'terminate'.

The 'book' says that Cocoa provides the global variable 'NSApp' to refer to the running application. So substituting 'NSApp' for 'NSApplication' doesn't change anything.

NSApplication doc says:
"... sharedApplication also initializes the global variable NSApp, which you use to retrieve the NSApplication instance. " -- So I assume that 'NSApp' points to my application's instance.


[NSApp terminate]; yields the SAME warning message as [[NSApplication sharedApplication] terminate]; -- so I'm assuming they're equivalent.

So I read further:
"... Another message, applicationShouldTerminate:, lets the delegate determine whether the application should be allowed to quit. The NSApplication class sends these messages directly to its delegate."


So maybe the solution is to fire off the message 'applicationShouldTerminate'?? to some delegate?

So, in brief...
To manually terminate an application, should I send a 'terminate' message to the NSApp's delegate?


Ric.



On Mar 30, 2004, at 2:00 PM, Shawn Erickson wrote:


On Mar 30, 2004, at 12:04 PM, Frederick C. Lee wrote:

Greetings:
	I tried to terminate an application manually, by calling my 'dealloc'
method.

Whose dealloc method? ...and are you actually calling it directly? If so you shouldn't do that but release as needed, which will get dealloc called for you automatically.


In it, I have [NSApp terminate] to terminate the application.
It appeared to be straight forward, but I've encountered the
'...selector not recognized'.

Question: what selector? ... and what's the remedy?

I think the below answers your question about which selector...

2004-03-30 11:53:06.281 AreaCode[3711] *** -[NSApplication terminate]:
selector not recognized

You are trying to send terminate to the NSApplication class not to an instance of that class, terminate is an instance method. You use sharedApplication to get your applications NSApplication instance.


[[NSApplication sharedApplication] terminate];

-Shawn
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.


References: 
 >Unable to Terminate Application (From: "Frederick C. Lee" <email@hidden>)
 >Re: Unable to Terminate Application (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: Unable to Terminate Application
  • Next by Date: Re: Unable to Terminate Application
  • Previous by thread: Re: Unable to Terminate Application
  • Next by thread: Problems compiling C files and adding them to my main project
  • Index(es):
    • Date
    • Thread