現在の日付/時刻をユーザーが選択した日付/時刻と比較する必要があります。以下は私のコードスニペットです
-(IBAction)btnSaveTouched:(id)sender {
NSDate *today = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd H:mm"];
NSString *formatterDate = [formatter stringFromDate: today];
NSComparisonResult comparisionResult1 = [self.paramSchedule1StartSQLDateString compare:formatterDate];
if (comparisionResult1 == NSOrderedAscending) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Viewing schedule must be after current time." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
return;
}
NSLog(@"comparisionResult1 %d", comparisionResult1);
}
btnSaveTouched(UIButton) がタップされると、日付/時刻がデータベースに保存され、画面に戻ります。(ユーザーが日付/時刻を選択するコントローラーを表示)
ただし、別の日付/時刻を比較しようとすると、現在の日付/時刻より後の日付/時刻を選択したにもかかわらず、アラートが表示されます。
NSLog の比較結果 1 の後、値は常に 2 回目のチェックで 1 です。私はこれをやろうとしました NSComparsionResult comparisionResult1 = 0; しかし、それは正しく機能していません。これを行う方法はありますか?
お知らせ下さい。ありがとう