|
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
@property (nonatomic, retain) NSDate *historyFromDate;
@property (nonatomic, retain) NSDate *historyToDate;
-(IBAction) fromDateChosen: (id)sender;
-(void) fetchTheHistory;-(void) setDates: (NSDate *)date
withType:(int) type;
@synthesize historyFromDate;
@synthesize historyToDate;
-(IBAction) fromDateChosen: (id)sender {
NSString *buttonTitle = @"I've chosen the 'FROM' date";
if ([[buttonDateChosen currentTitle] isEqualToString:buttonTitle]) {
NSLog(@"User has chosen the 'From' date");
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
// Get the chosen date value
NSDate *fromDate = [datePicker date];
// Set the 'to' date label to reflect the user's choice
labelFromDate.text = [dateFormatter stringFromDate:historyFromDate];
NSLog(@"'From' Date Chosen:%@", historyFromDate);
//[dateFormatter stringFromDate:[datePicker date]]);
[self fetchTheMoodHistory];
}
}
...
...
...
-(void) fetchTheHistory {
NSLog(@"Calling fetchTheHistory for the period from %@", historyFromDate);
...
...
}
You have to understand first that "class-level" variables don't exist, if you're defining the variable outside of an ivar block or a method it will be a global, this is evil btw.Now, if you're not using ARC (Automatic Reference Counting), then your date will be deallocated, trying to accessing it will result in a crash, or just display a broken value if you're lucky.I suggest to use a static variable if you really want a class-level variable, and I suggest making class-accessors. In any case the code you provide isn't really enough to provide a proper diagnostic, could you send your class implementation with the method implementations?Remy "Psy" DemarestLe 19 avr. 2012 à 13:44, The Rhythmic a écrit :_______________________________________________Am sorry to ask such a trivial question. Am a newbie to Objective-C, & simply cannot see how to get this working, after having tried several possible ways & google'd around for it. Please help!My question is simple. I have a class-level NSDate object, which is declared outside any method in the class as:NSDate *fromDate;Now, within a method, am setting this value to the date from a DatePicker as:fromDate = [datePicker date];Soon after the above assignment, I print its value into the log & it works fine.NSLog(@"From Date: %@", fromDate);Now, when I use NSDate's value in another/different method, the value's gone! Why is it not persisted across methods in the same class itself? What can I do for the value to be accessible across methods?
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (email@hidden)
This email sent to email@hidden
_______________________________________________ Do not post admin requests to the list. They will be ignored. Objc-language mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
| References: | |
| >NSDate value set in one method, is inaccessible from another (From: The Rhythmic <email@hidden>) | |
| >Re: NSDate value set in one method, is inaccessible from another (From: Remy Demarest <email@hidden>) |
| Home | Archives | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2011 Apple Inc. All rights reserved.