Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stadidas

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
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:
assetmonitor.png


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

macrumors regular
Original poster
Feb 27, 2006
243
0
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

macrumors regular
Original poster
Feb 27, 2006
243
0
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?
 

kpua

macrumors 6502
Jul 25, 2006
294
0
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.
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
kpua said:
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.
 

stadidas

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
caveman_uk said:
Ta very much!:D

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"
 

kpua

macrumors 6502
Jul 25, 2006
294
0
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.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
+initialize is almost certainly a bad time to be doing stuff like that. Try registering as NSApp's delegate and doing it in -applicationDidFinishLaunching.
 

alexhct

macrumors newbie
Nov 6, 2008
1
0
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. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.