我有一个带有多个警报的警报应用程序。
有一个 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"];
}
}
}