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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-20-2011, 01:39 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 3
abc23023 is on a distinguished road
Default 1 UIDatePicker, 2 NSDate's, and a whole lot of memory problems! Help!

Hello Everyone,

In one of my view's I have a UIDatePicker. I Also have 2 NSDate*'s initialized in the header (.h) file.
Code:
 @interface time : UIViewController {
NSDate* fromDate;
NSDate* toDate;
IBOutlet UIDatePicker *datePicker;
}

@property (nonatomic, retain) NSDate* fromDate;
@property (nonatomic, retain) NSDate* toDate;
@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;

-(IBAction)dateChanged:(id)sender; //this is linked to the UIdatePicker as an action
in the .m file, I have
Code:
 
- (IBAction)dateChanged:(id)sender {
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MMM dd hh:mma"];
    
    if (fromPressed) //either fromPressed or toPressed (Booleans) is True at one time!
    {
        fromDate = self.datePicker.date;
    }
    else if (toPressed)
    {
        toDate= self.datePicker.date;
    }
    [dateFormat release];
    
}
The problem is that I cannot set both of these dates from the picker. It only stores the most recently picked date and "corrupts" the other one. I think this is a memory management error (perhaps pointer related?).

Help is appreciated, thanks!
abc23023 is offline   Reply With Quote
Old 07-20-2011, 01:51 AM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Nvm, you aren't using your properties. The NSDate object isn't being retained and it is being auto released. Also get rid of your NSDateFormatter, you aren't using it.

Code:
- (IBAction)dateChanged:(id)sender {
    if (fromPressed) //either fromPressed or toPressed (Booleans) is True at one time!
    {
       self.fromDate = self.datePicker.date;
    }
    else if (toPressed)
    {
       self.toDate= self.datePicker.date;
    }

}
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.

Last edited by Domele; 07-20-2011 at 01:54 AM.
Domele is offline   Reply With Quote
Old 07-20-2011, 11:10 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 3
abc23023 is on a distinguished road
Default

Thanks Domele!

It worked like a charm! (Also, the DateFormatter was being used in the if loops to print out the date to the screen. I erased it as it was not pertinent to the problem at hand, but thanks for looking out for me!)

-abc23023
abc23023 is offline   Reply With Quote
Reply

Bookmarks

Tags
memory management, uidatepicker

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: 411
16 members and 395 guests
7twenty7, blasterbr, buggen, Clouds, dre, EvilElf, HemiMG, jeroenkeij, jimmyon122, jonathandeknudt, LEARN2MAKE, Mah6447, n00b, nyoe, pungs, UMAD
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,668
Threads: 94,121
Posts: 402,901
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jonathandeknudt
Powered by vBadvanced CMPS v3.1.0

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