0

セグメント化されたコントローラーと、24 時間のみを表示する UIDatePicker を含むビューがあります。セグメント化されたコントロールの内容に応じて、異なる時間を設定できるようにしたいと考えています。したがって、「Mon」はある時間に対応し、「Tue」は別の時間に対応します。私はこれを機能させています。ただし、ユーザーがセグメント化されたコントローラーのボタンを変更したときに、ピッカーをアニメーション化したいと思います。今のところ、セグメント化されたコントローラーにリンクされたアクションメソッドにこれがあります:

[timePicker setDate:date animate:YES];

date は次のようにフォーマットされた NSDate です: HH:mm

私が言ったように、それは日付に変わりますが、操作をアニメートしません。アニメ化しない理由わかる人いますか?

ところで、NSLog を使用して印刷する場合、フォーマッタを「HH:mm」に設定しましたが、それでも 1970-01-01 +02:00:00 文字列全体が印刷されます。とにかく、唯一の HH:mm が datepicker に送信され、すべてを出力するのは NSLog だけだと思いますか?

編集:これは実際のView Controllerのコードで、これは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
4

1 に答える 1

1

シミュレーターとデバイスの両方で、iOS4.0.1 SDK でもアニメーション化されません。4.0.1 より前に動作していたかどうかはわかりません。

試してみるには、次のコードをサンプル プロジェクト 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];

上記のメソッドも追加します - (void)viewDidLoad in PickerViewController.m

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

コードに基づいて、プロジェクトを実行し、ピッカーに移動し、UIDatePicker を選択し、日付ホイールを今日以外の日付にスピンし、[スピンミー] ボタンを押すと、ホイールが今日に戻るはずですが、そうではありません。 tアニメーション。

これが単なるバグなのか、回避策があるのか​​ を判断するのに苦労しています. setDate:animated: が機能していると聞いてかなり驚いています。

于 2010-07-25T03:10:51.153 に答える