0
我有一個包含多個警報的鬧鐘應用程序。無法在segue中設置UIDatePicker的日期
有一個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"];
}
}
}
謝謝!那是你隨着時間的推移而學到的東西,還是有一份文件可以指出你在哪裏學到的?它非常有意義.. –
@arigold,我認爲這是我從犯同樣的錯誤中學到的,並且做了一些研究來糾正它。 – rdelmar