• 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: NSTimer help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimer help


  • Subject: Re: NSTimer help
  • From: Ken Thomases <email@hidden>
  • Date: Wed, 17 Dec 2008 15:22:49 -0600

On Dec 17, 2008, at 3:02 PM, Eric Lee wrote:

Thanks...i hadn't realized there was a - (void)windowShouldClose..but now I have another problem.

Well, there isn't. There's a -(BOOL)windowShouldClose:. Note the return type.


Also note that -windowShouldClose: is invoked by -performClose: but not by -close. That is, it's not always guaranteed to be called before a window is closed.


I have implemented an if/else statement so that I can determine if something is happening

However, even though the if statement is true, the window never closes:

Here's the code...thanks

- (void)windowShouldClose:(id)window

Again, the proper return type for this method is BOOL. It's supposed to return whether the window should be close.


{
	if ([[textField stringValue] isEqualTo: @"0:00:00" || @"0.00000" ]) {

What's up with the above line? First, you should be careful about which isEqual... method you use. -isEqual: is a generic method for comparing any two objects. Since you know you're comparing strings, you should use -isEqualToString:. Don't use -isEqualTo: unless you're specifically working with scripting -- it's scripting-specific, although in most cases it is equivalent to -isEqual:.


But more importantly, you have a serious syntax problem on the above line. How are you expecting that 'or' operation (||) to work? You're or-ing two string object pointers. Since neither is going to be nil, the 'or' will evaluate to true. You are then passing this true value as the parameter to -isEqualTo:. -isEqualTo: is expecting an object pointer, not a boolean value. It's almost certainly going to crash.


[mainWindow windowShouldClose:YES];

Now you're sending the windowShouldClose: message to a window. But - windowShouldClose: is not a method on NSWindow. It's a method for a window delegate.


Furthermore, you're passing YES as the parameter, although the parameter type is id, an object pointer.

Perhaps you just meant to return YES, indicating that the window for which self is a delegate should close?

}

else {

NSAlert *alert;
alert = [NSAlert alertWithMessageText:@"Error!" defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:@"Please stop the timer."];

[alert runModal];

[mainWindow windowShouldClose:NO];

Same as above.

	}
}


Forgive me for saying so, but you seem like you're in WAY over your head. You should really review some basic programming guides, then the basics of Objective-C, then the basics of Cocoa.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTimer help
      • From: Andrew Farmer <email@hidden>
References: 
 >NSTimer help (From: Eric Lee <email@hidden>)
 >Re: NSTimer help (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: NSTimer help
  • Next by Date: Fwd: keychain -- "Changed software confirmation dialog"
  • Previous by thread: Re: NSTimer help
  • Next by thread: Re: NSTimer help
  • Index(es):
    • Date
    • Thread