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

Brendan.Porter

Contributor
Original poster
May 19, 2007
37
1
Twin Cities Metro
I'm trying to simply place the TIME from a UIDatePicker into a UITextField.
I am beating my head against the wall looking at the code for the last week.

The code I have is currently:
-(void) createDatePicker
{
[myDatePicker = [UIDatePicker alloc] awakeFromNib];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString* currentTime = [dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release];

}

In my head the 7th line's "currentTime" should hold the date now in a string. However, in another method when I try to set the text of the UITextField to currentTime, nothing happens.

- (IBAction) buttonPress: calculateButton
{
[timeInField setText:currentTime];
}

Any help?
 

Brendan.Porter

Contributor
Original poster
May 19, 2007
37
1
Twin Cities Metro
Ok, I get that.
I have a declaration of currentTime as an NSString in the header, so that isn't necessary.

I've changed the code a bit, and now do not receive warnings.
However, the text from theTime still does not put itself into the UITextField.

I've even prototyped the plumbing by placing a test string within the function that is supposed to put the date into UITextField, and that string does show in the field properly when the button is pressed. This tells me that I'm missing a critical piece of plumbing to either get the value of [myDatePicker date] into theTime, or theTime looses the value outside of the createDatePicker function.
I even tried a [theTime retain], but that didn't help.

-(void) createDatePicker
{
[myDatePicker = [UIDatePicker alloc] awakeFromNib];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
theTime = [dateFormatter stringFromDate:[myDatePicker date]];
[dateFormatter release];

}


- (IBAction) buttonPress: calculateButton
{
NSString* tryThisString = @"Test";
[timeInField setText:[tryThisString description]];
}



Any further help would be greatly appreciated.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.