【发布时间】:2014-05-08 09:20:21
【问题描述】:
应用程序在调用此函数时崩溃了,但在 iPhone 中它工作正常,但在 iPad 中应用程序崩溃并说
注意:我正在使用 ActionSheetDatePicker 库
线程 1:EXC_BAD_ACCESS(cod = 1,地址 = 0x9e...)
当我调试时,我发现 selectedDate 在 iPad 中为 nil,但在 iPhone 中可以正常工作
#pragma mark - Implementation
- (void)dateWasSelected:(NSDate *)selectedDate element:(id)element {
// self.selectedDate = selectedDate;
//may have originated from textField or barButtonItem, use an IBOutlet instead of element
//DATE TEXT FIELD HERE
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd"];
//Optionally for time zone converstions
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"..."]];
NSString *stringFromDate = [formatter stringFromDate:selectedDate];
self.textFieldBirthDate.text = stringFromDate ;
birthDate = stringFromDate ;
//"YYYY-MM-DD" the birthdate format
}
【问题讨论】:
-
一般情况下,ActionSheet 默认使用 UIPopover,因此您会遇到困难,因此请您发布更多代码,以便调试。您也可以通过检查所选日期是否为 nil 来避免此崩溃,如果为 nil 则返回当前日期
-
我正在使用这个库github.com/TimCinel/ActionSheetPicker 并且代码在他没有进入函数的函数行上崩溃了,它只是在函数头上得到这条绿线并停止,它的iPhone的相同代码,我只是将故事板从iPhone复制到iPad并调整大小,相同的代码我不知道会发生什么
标签: ios datepicker