0
#import "DatePickerViewController.h"
#import <Parse/Parse.h>

@interface DatePickerViewController ()


@end

@implementation DatePickerViewController

@synthesize dateLabel;
@synthesize pick;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    UIBarButtonItem *saveDate = [[UIBarButtonItem alloc]
                                 initWithTitle:@"Save Date"
                                 style:UIBarButtonItemStyleDone
                                 target:self
                                 action:@selector(saveList:)];
    self.navigationItem.rightBarButtonItem = saveDate;
    pick = [[UIDatePicker alloc] init];
    [pick setFrame:CGRectMake(0,200,320,120)];
    [pick addTarget:self action:@selector(updateDateLabel:) forControlEvents:UIControlEventValueChanged];


}

-(void)saveList:(id)sender {
    // need to finish

}

-(IBAction)updateDateLabel {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterLongStyle];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    dateLabel.text = [NSString stringWithFormat:@"%@", [formatter stringFromDate:pick.date]];

}
4

2 に答える 2

1

ピッカーからのイベントの登録では、1つの引数を期待する(@selector(updateDateLabel:)形式のメソッドを期待する-updateDateLabel:(id)arg)セレクターを使用していますが、実装したものは引数を取りません(-updateDateLabel

もちろん、ストーリーボードからアーカイブ解除されたピッカーからピッカーを再割り当てしたことを考えると、これはすべて意味がありません。初期化コードを削除し、ストーリーボードのピッカーにIBActionを接続します。

于 2013-03-16T21:03:14.403 に答える
0

-(IBAction)updateDateLabel {に変更-(IBAction)updateDateLabel:(id)sender {

于 2013-03-16T21:06:52.430 に答える