Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode UIDatePicker未更新UILabel_Xcode_Ios5_Uidatepicker - Fatal编程技术网

Xcode UIDatePicker未更新UILabel

Xcode UIDatePicker未更新UILabel,xcode,ios5,uidatepicker,Xcode,Ios5,Uidatepicker,我有一个UIDatePicker,试图根据用户选择的日期实时更新UILabel。如果用户选择了一个日期(比如2012年1月21日),然后改变主意(比如2013年3月21日),我希望UILabel反映这一变化 到目前为止,UILabel只反映当前日期,即使用户从UIDatePicker中选择了另一个日期,也不会更新其文本。我也搜索了一些指针来解决这个问题,但没有结果。任何帮助都将不胜感激。谢谢 迄今为止的代码: .h文件,我有 @property (strong, nonatomic) IBOut

我有一个UIDatePicker,试图根据用户选择的日期实时更新UILabel。如果用户选择了一个日期(比如2012年1月21日),然后改变主意(比如2013年3月21日),我希望UILabel反映这一变化

到目前为止,UILabel只反映当前日期,即使用户从UIDatePicker中选择了另一个日期,也不会更新其文本。我也搜索了一些指针来解决这个问题,但没有结果。任何帮助都将不胜感激。谢谢

迄今为止的代码: .h文件,我有

@property (strong, nonatomic) IBOutlet UILabel *entryDateSetLabel;
@property (strong, nonatomic) IBOutlet UIDatePicker *entryDateSelected;

- (IBAction)datePickerDateChanged:(id)sender;
datePickerDateChanged连接到日期选择器的值更改事件

.m文件

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.entryDateSelected = [[UIDatePicker alloc] init];

    [self.entryDateSelected addTarget:self action:@selector(datePickerDateChanged:) forControlEvents:UIControlEventValueChanged];
}

- (IBAction)datePickerDateChanged:(id)sender {

    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
    [outputFormatter setDateFormat:@"MMMM d, yyyy"];

    NSString *entryDateInString = [outputFormatter stringFromDate:self.entryDateSelected.date];

    [[self entryDateSetLabel] setText: entryDateInString];
}
截图

在“值更改”事件和

使用这个代码我从其他地方复制了它,所以你必须做一些更改

NSDate *today1 = pkrViewDate.date;
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
NSString *dateString11 = [dateFormat stringFromDate:today1];
lblDate.text=dateString11;
ans还检查滚动日期选择器时“datePickerDateChanged”方法是否正在调用。

刚刚修复了该问题。:-)

viewDidLoad应为

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSDate *now = [NSDate date];
    [_entryDateSelected setDate:now animated:YES];

     //self.entryDateSelected = [[UIDatePicker alloc] init];

    [self.entryDateSelected addTarget:self action:@selector(datePickerDateChanged:) forControlEvents:UIControlEventValueChanged];
}

希望这对其他人有所帮助。

在“值更改”事件中连接数据选择器这里是“pkrViewDate”是UIDatePicker的名称。您好Vishal,感谢您的帮助。。。我已经将日期选择器连接到值更改事件。我理解你的答案,除了
obj_AppDelegate.strIncomeDate
位。你能再解释一下吗?ThanksI告诉你我复制了它……所以“obj_AppDelegate.strIncomeDate=dateString11”;您不需要这段代码……但在这一行中,我将“dateString11”的值赋给AppDelegate中声明的“strIncomeDate”。