У меня есть кнопка, которая отображает часы - при загрузке представления устанавливается текущее время.
Затем, когда я загружаю подпредставление выбора даты, оно всегда устанавливается на 2 часа раньше.
что-то вроде того:
Кнопка даты: 10:31 Выбор даты: 12:31
после изменения часа в средстве выбора даты на: 13:31 кнопка даты изменится на: 11: 31.
код:
-(IBAction) timeClicked
{
[[NSBundle mainBundle] loadNibNamed:@"timePicker" owner:self options:nil];
//timeView = [[UIView alloc]initWithNibName:@"timePicker" bundle:nil];
[timeView setFrame:CGRectMake(0, 480, 320, 431)];
NSLog(@"time clicked date: %@", select);
NSDate* sourceDate = [NSDate date];
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithName:@"Jerusalem"];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];
//[timePick setTime:destinationDate animated:YES];
timePick.date=destinationDate;
NSLog(@"befoer delegate");
//[timeView setDelegate:self];
[self.view addSubview:timeView];
CGRect frame = timeView.frame;
frame.origin.y = 110;
[UIView beginAnimations:nil context:NULL];
timeView.frame = frame;
[UIView commitAnimations];
NSLog(@"after");
}
-(IBAction) done
{
select = [timePick date];
[UIView beginAnimations:@"RemoveDatePicker" context:NULL];
[UIView setAnimationDidStopSelector:@selector(transitionDidStop:finished:context:)];
CGRect rect = timeView.frame;
rect.origin.y = 460;
timeView.frame = rect;
[UIView commitAnimations];
}
- (void)transitionDidStop:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
if ([animationID isEqualToString:@"RemoveDatePicker"]){
[timeView removeFromSuperview];
NSLog(@"RemoveDatePicker");
}
}
-(IBAction) timeChanged
{
select =[timePick date];
[timeButton setTitle:[Path stringFromTime:select] forState:UIControlStateNormal];
//[timeButton setTitle:@"time" forState:UIControlStateNormal];
}
+(NSString *) stringFromTime: (NSDate *) date
{
NSString * stringDate = [date description];
stringDate = [[stringDate substringFromIndex:11] substringToIndex:5];
NSLog(@"[Path]stringTime: %@", stringDate);
return stringDate;
}
с точки зрения загрузки:
NSDate* sourceDate = [NSDate date];
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithName:@"Jerusalem"];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];
timeModeChange.selectedSegmentIndex=1;
select=[[NSDate alloc]initWithDate:destinationDate ];
NSLog(@"date %@", select);
[timeButton setTitle:[Path stringFromTime:select] forState:UIControlStateNormal];