Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 947087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:01:39+00:00 2026-05-15T23:01:39+00:00

I have a view containing a segmented controller and a UIDatePicker that only shows

  • 0

I have a view containing a segmented controller and a UIDatePicker that only shows 24-h time. I want to be able to set different times depending on what the segmented control says. So “Mon” would correspond to one time, “Tue” to another and so on. I have this working. However, I also would like to animate the picker when the user changes button on the segmented controller. As of now I have in my action method linked to the segmented controller this:

[timePicker setDate:date animate:YES];

Where date is a NSDate formatted like so: HH:mm

As I said, it will change to the date but it will not animate the operation. Anyone knows why it doesn’t animate?

BTW, although I have set the formatter to be “HH:mm” if I use NSLog to print it I still get the whole 1970-01-01 +02:00:00 string printed. I assume that the only HH:mm is sent to the datepicker anyway and that it is just NSLog that prints the whole thing?

EDIT: Here is the code for the actual view controller, and this is running SDK4

#import "FlipsideViewController.h"

@implementation FlipsideViewController

@synthesize delegate, times, weatherImage, condition, timePicker;


- (void)viewDidLoad {

    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];

    UIImage *image = [UIImage imageNamed:@"sunny.png"];
    weatherImage.image = image;

    WeatherClockAppDelegate *appDelegate = (WeatherClockAppDelegate *)[[UIApplication sharedApplication] delegate];

    times = appDelegate.times;

    [timePicker addTarget:self action:@selector(timePickerAction:) forControlEvents:UIControlEventValueChanged];

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"HH:mm"];
    NSDate *sunnyDate = [df dateFromString: [times objectAtIndex:0]];
    [df release];

    [timePicker setDate:sunnyDate animated:NO];


}

- (IBAction)done:(id)sender {

    if (!busy) {

        [self.parentViewController dismissModalViewControllerAnimated:YES];

        for (NSString *s in times) {
            NSLog(@"Set times: %@", s);
        }
    }

}

- (IBAction)segmentedAction {

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"HH:mm"];

    switch (self.condition.selectedSegmentIndex) {

        case 0:

            self.weatherImage.image = [UIImage imageNamed:@"sunny.png"];

            NSDate *sunnyDate = [df dateFromString: [times objectAtIndex:0]];

            [timePicker setDate:sunnyDate animated:YES];

            break;

        case 1:

            self.weatherImage.image = [UIImage imageNamed:@"cloudy.png"];

            NSDate *cloudyDate = [df dateFromString: [times objectAtIndex:1]];

            NSLog(@"Cloudydate: %@", cloudyDate);

            [timePicker setDate:cloudyDate animated:YES];

            break;

        case 2:

            self.weatherImage.image = [UIImage imageNamed:@"rain.png"];

            NSDate *rainyDate = [df dateFromString: [times objectAtIndex:2]];

            [timePicker setDate:rainyDate animated:YES];

            break;

        case 3:

            self.weatherImage.image = [UIImage imageNamed:@"final.png"];

            NSDate *finalDate = [df dateFromString: [times objectAtIndex:3]];

            [timePicker setDate:finalDate animated:YES];

            break;

    }

    [df release];
}


- (IBAction)timePickerAction:(id)sender {

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"HH:mm"];
    NSString *date = [NSString stringWithFormat:@"%@", [df stringFromDate:timePicker.date]];
    NSLog(@"%@", date);
    [df release];

    switch (self.condition.selectedSegmentIndex) {

        case 0:

            [times replaceObjectAtIndex:0 withObject:date];

            break;

        case 1:

            [times replaceObjectAtIndex:1 withObject:date];

            break;

        case 2:

            [times replaceObjectAtIndex:2 withObject:date];         

            break;

        case 3:

            [times replaceObjectAtIndex:3 withObject:date];

            break;

    }

}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}


- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */


- (void)dealloc {

    [times release];
    [weatherImage release];
    [condition release];
    [timePicker release];
    [super dealloc];
}


@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:01:40+00:00Added an answer on May 15, 2026 at 11:01 pm

    It’s not animating for me too on iOS4.0.1 SDK, both on simulator and device. No idea if it was working before 4.0.1.

    To try it out, add the following code into the sample project UICatalog, PickerViewController.m in – (void)viewDidLoad

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = labelFrame;
    [button setTitle:@"Spin me" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(spin) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    

    Add also a method above – (void)viewDidLoad in PickerViewController.m

    - (void) spin {
        [datePickerView setDate:[NSDate date] animated:YES];
    }
    

    Based on the code, if you run the project, navigate to Pickers, select UIDatePicker, spin the date wheel to any date other than today, hit the ‘Spin Me’ button, it should set the wheel back to today, BUT it wouldn’t animate.

    I’m having a hard time figuring out if this is just a bug, and if there’s any workaround. Pretty surprise to hear that setDate:animated: is working for some of you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a View Controller containing a UITableView that used an NSMutableArray to determine
I have a view containing a button. And i want to perform an action
Using storyboard, I have a table view controller containing multiple dynamic prototype cells. One
I have a table containing view/click records. The time is stored in a unix
I have an application containing a variety of view controllers linked together in different
I have a view controller (derived from UIViewController not UITableViewController) containing a table view.
I have a UINavigationController in which I am loading different view controllers. I want
I have setup a basic test app that displays a view containing a label,
I have a User model. It has register view containing a form that looks
please i have a view containing 3 buttons and i want to switch to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.