NSDateFormatter を使用して日付をフォーマットしようとしていますが、アプリが EXC_BAD_ACCESS でクラッシュします。
コードは次のとおりです。
DateInputTableViewCell *cell0 = (DateInputTableViewCell *)[paramTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
DateInputTableViewCell *cell1 = (DateInputTableViewCell *)[paramTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
NSString *fromDate = [[Helpers defaultFormatter] stringFromDate:cell0.dateValue];
NSString *toDate = [[Helpers defaultFormatter] stringFromDate:cell1.dateValue];
上記のコードは、私が持っている 2 つのカスタム UITableViewCell から日付を取得しています。値は null ではありません (テスト済み)。しかし、ヘルパー クラスから defaultFormatter メソッドを使用しようとすると、アプリがクラッシュします。以下はコードです:
+ (NSDateFormatter *)defaultFormatter{
defaultFormatter = [[NSDateFormatter alloc] init];
NSLocale* locale = [[NSLocale alloc] initWithLocaleIdentifier:@"pt_BR"];
[defaultFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"America/Sao_Paulo"]];
[defaultFormatter setDateFormat:@"yyyy'-'MM'-'dd' 'HH':'mm':'ss"];
[defaultFormatter setLocale:locale];
[locale release];
return defaultFormatter;
}
カスタム UITableViewCell の NSDateFormatter は次のように定義されます。
self.dateFormatter = [[NSDateFormatter alloc] init];
self.dateFormatter.timeStyle = NSDateFormatterNoStyle;
self.dateFormatter.dateStyle = NSDateFormatterMediumStyle;
ここで同様の質問をいくつか見ましたが、この問題を解決できませんでした!
前もって感謝します!
編集