0

我有一个显示时间的 UIButton,这个时间显示在 UIButton 的 titleLabel 属性中。要更改此时间,您可以单击按钮,该按钮会调用此方法来引入日期选择器。

- (IBAction)slidePickerIn:(id)sender {
    // Ok button to dismiss picker
    [self.view bringSubviewToFront:self.datePickerOK];
    // Bring picker to front
    [self.view bringSubviewToFront:self.datePicker];
    // animate entrance of picker and fade in of dismiss button
    [UIView animateWithDuration:.5 animations:^{
        [self.datePicker setFrame:pickerIn];
        self.datePickerOK.alpha = 1;
    }];
}

当您单击关闭按钮时,将调用此方法。它摆脱了日期选择器和关闭按钮,并更新了显示时间的按钮的标题。

- (IBAction)slideDatePickerOut {
    [UIView animateWithDuration:.5 animations:^{
        self.datePickerOK.alpha = 0;
        [self.datePicker setFrame:pickerOut];
    }];

    // Set time correctly
    NSDate *wake = self.datePicker.date;
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"hh:mm a"];
    self.wakeUpTime.titleLabel.text = [NSString stringWithFormat:@"%@", [df stringFromDate:wake]];
    self.wakeUpTime.date = wake;
}

屏幕上还有另一个按钮,它也调用 slidePickerIn 并允许您更改时间。

问题:当我单击另一个按钮更改显示的日期时,一切正常。但是,当我单击包含显示时间的标题的按钮本身时,日期变为 00:00 AM(默认值),同时显示日期选择器。当日期选择器被关闭时,时间会正确更新。但正如我所说,使用另一个按钮不会更改显示选择器时的时间值。我真的不确定为什么会这样。任何帮助将非常感激。

4

2 回答 2

0

在你的 slidePickerIn 添加:

if(self.datePicker.alpha == 0)
{
    //Add all the methods
}

在您的 slidePickerOut 添加:

if(self.datePicker.alpha == 1)
{
    //Add all the methods
}

现在 UIButtons 将在正确的时间被调用。

于 2013-07-27T13:33:17.210 回答
0

确保您没有将两种方法都分配给按钮

于 2013-07-27T15:31:03.660 回答