Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 28, 2006, 10:22 AM   #1
stadidas
macrumors regular
 
Join Date: Feb 2006
Location: Kent, United Kingdom
Set NSDatePicker to System Time

At Uni last year I wrote a program in pure Java to help manage my money. Recently I've decided to re-write this program using Cocoa and Objective-C.
I've worked out most of the back-end of it, but there's one thing I need to sort out first.
Here is the prototype interface I've been working on:


I would like to be able to set the top NSDatePicker to the current system date. I would then use the value from the user-definable NSDatePicker at the bottom to calculate how long is left in the current term.
If anyone knows how to set an NSDatePicker to the current system time I would be grateful if you let me know!
stadidas is offline   0 Reply With Quote
Old Jul 28, 2006, 10:35 AM   #2
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
Just looking at the docs have you tried

[datePickerObject setDateValue:[NSDate date]];
caveman_uk is offline   0 Reply With Quote
Old Jul 28, 2006, 10:43 AM   #3
stadidas
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Location: Kent, United Kingdom
I shall give that a try when I get down to coding it.
By the way, Beer Alchemy looks awesome! One of my mates at Uni is buying a MacBook Pro soon, and he brews beer, so he'll be buying a license, he looked impressed by your app.
stadidas is offline   0 Reply With Quote
Old Jul 28, 2006, 02:10 PM   #4
stadidas
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Location: Kent, United Kingdom
I've made a test project to try and get this NSDatePicker setting to work.
I have an NSDatePicker called currentDate defined in my header file. I have written a method called setDate which I call from the + (void)Initialize function. The setDate function looks like this:
Code:
- (void)setDate
{
	[currentDate setDateValue:[NSDate date]];
}
I call it from the Initialize function by doing [self setDate]; but I get a warning and it doesn't seem to work. I'm new to this Objective C lark and am probably doing something very stupid. Anyone know what I'm doing wrong?
stadidas is offline   0 Reply With Quote
Old Jul 28, 2006, 03:41 PM   #5
kpua
macrumors 6502
 
Join Date: Jul 2006
Perhaps if you told us what the warning you're getting is, we could help you easier...

Also, it looks like you have your class's +initialize method called +Initialize, which isn't the same thing, and it's probably never getting called since you're not overriding the correct method.
kpua is offline   0 Reply With Quote
Old Jul 28, 2006, 03:43 PM   #6
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
Quote:
Originally Posted by stadidas
By the way, Beer Alchemy looks awesome!
Ta very much!
Quote:
I call from the + (void)Initialize function
Is there any reason why you're using that? I'd do it in -init. Do you know the difference between the - and + methods. (Just asking)?
caveman_uk is offline   0 Reply With Quote
Old Jul 28, 2006, 03:44 PM   #7
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
Quote:
Originally Posted by kpua
Also, it looks like you have your class's +initialize method called +Initialize, which isn't the same thing, and it's probably never getting called since you're not overriding the correct method.
Good point...I didn't spot that.
caveman_uk is offline   0 Reply With Quote
Old Jul 28, 2006, 04:55 PM   #8
stadidas
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Location: Kent, United Kingdom
Quote:
Originally Posted by caveman_uk
Ta very much!

Is there any reason why you're using that? I'd do it in -init. Do you know the difference between the - and + methods. (Just asking)?
I am using the initialize function, shouldn't have capitalised it.
The - methods are instance methods, and + are class methods I think. Still not sure whether they're supposed to be called functions or methods (I tend to think of them as methods as I come from a Java background).

I've now put this code in:
Code:
- (void) init
{
	[self setDate];
}
I get an warning saying: 'Converter' may not respond to '-setDate'. When I try and run the app the XCode run log says:
"[Session started at 2006-07-28 22:53:29 +0100.]
2006-07-28 22:53:30.330 NSDatePickerTest[1309] *** -[NSCFArray addObject:]: attempt to insert nil"
stadidas is offline   0 Reply With Quote
Old Jul 28, 2006, 06:19 PM   #9
kpua
macrumors 6502
 
Join Date: Jul 2006
Looks like you've got two problems that may or may not be connected.

First, the compiler can't find a -setDate method for your Converter class. Did you declare one in a .h file?

Second, you think you're adding something to an array, but you're not (you're trying to add nil instead of a valid pointer). I would break on -[NSException raise] in the debugger to see why that pointer is nil.
kpua is offline   0 Reply With Quote
Old Jul 28, 2006, 08:05 PM   #10
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
+initialize is almost certainly a bad time to be doing stuff like that. Try registering as NSApp's delegate and doing it in -applicationDidFinishLaunching.
Catfish_Man is offline   0 Reply With Quote
Old Nov 7, 2008, 01:41 AM   #11
alexhct
macrumors newbie
 
Join Date: Nov 2008
Quote:
Originally Posted by stadidas View Post
I am using the initialize function, shouldn't have capitalised it.
The - methods are instance methods, and + are class methods I think. Still not sure whether they're supposed to be called functions or methods (I tend to think of them as methods as I come from a Java background).

I've now put this code in:
Code:
- (void) init
{
	[self setDate];
}
I get an warning saying: 'Converter' may not respond to '-setDate'. When I try and run the app the XCode run log says:
"[Session started at 2006-07-28 22:53:29 +0100.]
2006-07-28 22:53:30.330 NSDatePickerTest[1309] *** -[NSCFArray addObject:]: attempt to insert nil"
I think, you have following 3 issues: I had those previousely
1. in your header file, you need to declare the setDate method like
-(void) setDate;
this will help for the warmming at compile time

2. in the init function, you need to return the object
please note, you don't set time here, the datepicker obj is not ready yet
-(id)init
{
return self;
}

3. add another method in your .m file and run your setDate here
-awakeFromNib
{
[self setDate];
}

try above three steps.
alexhct is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How to set defaults for default operating system? ugr Windows, Linux & Others on the Mac 1 Mar 4, 2014 07:39 PM
how to set up a digital signage system using macs rooster676 Mac Basics and Help 1 Aug 2, 2013 07:02 AM
System 7.5-style icon set? Kaji OS X 0 Jun 11, 2012 10:35 PM
Apple to Unveil Television Set Operating System at WWDC? MacRumors MacRumors.com News Discussion 189 Jun 10, 2012 09:11 AM

Forum Jump

All times are GMT -5. The time now is 04:15 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC