0

我有一个带有多个警报的警报应用程序。

有一个 AlarmListViewController 是一个 UITableView 保存警报列表。选择该行时,将启动一个到 AlarmViewController(详细视图)的 segue。除日期外,其他所有内容都正确地从 AlarmListViewController 传递到 AlarmViewController。

我应该提到这fullDate是 NSDate 上的一个类别,使 NSDates 的打印更容易。

这是代码:

标题:

AlarmViewController.h

@interface AlarmViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UIDatePicker *timeSelected;
@property (nonatomic, strong) NSMutableArray *repeatSelection;
@property (nonatomic, strong) NSString *alarmID;

@end

执行:

AlarmViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"---VIEW DID LOAD---, current date: %@", [[NSDate date] fullDate]);
    NSLog(@"alarmID: %@", self.alarmID);
    NSLog(@"repeat: %@", self.repeatSelection);
    NSLog(@"time: %@", [self.timeSelected.date fullDate]);

}

prepareForSegue:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"self.selectedCell: %d", self.selectedCell);
    if ([segue.identifier isEqualToString:@"alarmDetail"] || [segue.identifier isEqualToString:@"addAlarm"])
    {
        AlarmViewController *aVC = (AlarmViewController *)[segue destinationViewController];
        if (self.tableView.editing)
        {
            NSDictionary *setting = [self.alarmList objectAtIndex:self.selectedCell];
            NSLog(@"setting.time = %@", [[setting objectForKey:@"time"] fullDate]);

            aVC.repeatSelection = [setting objectForKey:@"repeat"];
            aVC.alarmID = [setting objectForKey:@"alarmID"];
            aVC.timeSelected.date = [setting objectForKey:@"time"];
        }
    }
}
4

1 回答 1

1

您不能在加载视图之前设置 UI 元素的值,这是您在从 prepareForSegue 设置日期选择器的日期时尝试执行的操作。相反,您需要将日期传递给 aVC,然后在其 viewDidAppear 方法中,将日期选择器的日期设置为传入的日期(您需要 aVC 中的属性来保存该日期)。

于 2013-02-04T04:47:27.173 回答