为什么我的UILabel没有随着datepicker的更改而更新? [英] Why is my UILabel not updating as the datepicker changes?

查看:79
本文介绍了为什么我的UILabel没有随着datepicker的更改而更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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]];

}


推荐答案

您的注册对于来自picker的事件,使用一个需要一个参数的选择器( @selector(updateDateLabel :))/ / code>需要一个 -updateDateLabel形式的方法:(id )arg ),而你实现的不带参数( -updateDateLabel

Your registration for events from the picker is using a selector that expects one argument (@selector(updateDateLabel:) expects a method of the form -updateDateLabel:(id)arg), whereas what you have implemented takes no arguments (-updateDateLabel)

当然,考虑到你已经从故事板上解压缩了你的选择器,所有这一切都没有实际意义。删除初始化代码并将IBAction连接到故事板中的选择器。

Of course, all of this is moot considering that you've reassigned your picker from the one that was de-archived from the storyboard. Remove the initialization code and hook up the IBAction to the picker in the storyboard.

这篇关于为什么我的UILabel没有随着datepicker的更改而更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆