0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UIPickerViewに初期値を設定する

0
Last updated at Posted at 2015-04-15

UIPickerViewに初期値を設定しようと思ったが、ググって出てくる方法だと設定出来なくなっているので、自分のために記録しておく。

ググってよく出てくるのが、

    [pickview setDate: [NSDate alloc] initWithString:"…………"];

というものだが、なぜかNSDateにはinitWithStringは無いと言われる。
なので下記のような方法で設定した。

    NSString *alarmtime = @"1200";
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"HHmm"];
    NSDate *alarmdate = [df dateFromString:alarmtime];
    [pickview setDate:alarmdate];

この方法で正しく初期値を設定出来た。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?