Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Mac OS X Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-03-2010, 06:53 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 14
bodalal is on a distinguished road
Default what's wrong with this code? date calculate

this is for Mac app not iphone

it should calculate years, months and days between tow date

but it does not work, nothing show up in the Labels (ddrsltY , ddrsltM and ddrsltD )

can any one help me plz, what is the wrong and how can i fix it ?

Code:
#import "DDateCompnt.h"

@implementation DDateCompnt
- (IBAction)ddCalc:(id)sender {
		
			
	NSDate *dateNow = [[NSDate alloc] init]; // The current date
	NSDate *endDate = ddbirth;
	
	NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
	
	NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
	
	NSDateComponents *components = [gregorian components:unitFlags fromDate:endDate toDate:dateNow options:0];
	
    int years = [components year];
	int months = [components month];
	int days = [components day];
		
	[ddrsltY setIntValue:years]; 	
	[ddrsltM setIntValue:months];
	[ddrsltD setIntValue:days];


	
}



@end
bodalal is offline   Reply With Quote
Old 07-04-2010, 10:36 AM   #2 (permalink)
Maker of Games
 
Mr Jack's Avatar
 
Join Date: Nov 2009
Location: Coventry, UK
Posts: 395
Mr Jack is on a distinguished road
Default

Have you tried putting a breakpoint in, and stepping through to see what values you are getting?
__________________


Visit Mr Jack Games for my blog and more about my games
Mr Jack is offline   Reply With Quote
Old 07-04-2010, 11:44 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 14
bodalal is on a distinguished road
Default

Thanx for your reply

no i didn't, i do not know how to !

it looks like every thing is OK, i don't know why there is nothing show up in the labels


thanx any way
bodalal is offline   Reply With Quote
Old 07-04-2010, 01:17 PM   #4 (permalink)
Maker of Games
 
Mr Jack's Avatar
 
Join Date: Nov 2009
Location: Coventry, UK
Posts: 395
Mr Jack is on a distinguished road
Default

Quote:
Originally Posted by bodalal View Post
no i didn't, i do not know how to !
It's really easy. I assume you're using XCode? Right click in the gutter to the left of your code, and choose add breakpoint. Do this on the first line of the function you want to debug.

Then, making sure the enable breakpoints option is set, and that you've chosen the debug build of your code (in the drop-down near the top left), click the Build and Debug button.

Then bring up the debugger. I can't remember off hand which one of the menu headings its under, just look through until you find it.

Then do whatever should cause your code to be run, and make sure that it's stopped at your breakpoint*. You can now step through your code line-by-line using the buttons in the debugger, and see what each of the variables are set to in the watch window, or by hovering your mouse over the variable of interest.

This should help you identify the problem.


* - if it doesn't get triggered, your problem is most likely you're not calling your code.
__________________


Visit Mr Jack Games for my blog and more about my games
Mr Jack is offline   Reply With Quote
Old 07-12-2010, 09:44 PM   #5 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 155
barrettj is on a distinguished road
Default

Quote:
Originally Posted by bodalal View Post
this is for Mac app not iphone

it should calculate years, months and days between tow date

but it does not work, nothing show up in the Labels (ddrsltY , ddrsltM and ddrsltD )

can any one help me plz, what is the wrong and how can i fix it ?

Code:
#import "DDateCompnt.h"

@implementation DDateCompnt
- (IBAction)ddCalc:(id)sender {
		
			
	NSDate *dateNow = [[NSDate alloc] init]; // The current date
	NSDate *endDate = ddbirth;
	
	NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
	
	NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
	
	NSDateComponents *components = [gregorian components:unitFlags fromDate:endDate toDate:dateNow options:0];
	
    int years = [components year];
	int months = [components month];
	int days = [components day];
		
	[ddrsltY setIntValue:years]; 	
	[ddrsltM setIntValue:months];
	[ddrsltD setIntValue:days];


	
}



@end

Are you sure you hooked up the action in interface builder and saved the file (I ALWAYS forget to save)?

You can double check if your selector is running by adding a NSLog(@"my method was called!"); and checking the console to make sure that appears.
barrettj is offline   Reply With Quote
Old 07-13-2010, 04:46 AM   #6 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 14
bodalal is on a distinguished road
Default

Quote:
Originally Posted by barrettj View Post
Are you sure you hooked up the action in interface builder and saved the file (I ALWAYS forget to save)?

You can double check if your selector is running by adding a NSLog(@"my method was called!"); and checking the console to make sure that appears.
thanx allot .. you'r right, the problem was in connections in IB.

it works now
bodalal is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 460
17 members and 443 guests
alexeir, David-T, Dj_kades, foslock, iAppDeveloper, j.b.rajesh@gmail.com, jeroenkeij, mer10, Mijator, mkjarred, myach, pipposanta, QuantumDoja, robsmy, sacha1996, SLIC, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,129
Posts: 402,928
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0