我想从我的DatePicker中读取值并将其存储在我的单例中,但在尝试执行此操作时会出现异常。
这是单身人士界面:
@interface Helper : NSObject {
NSMutableArray *array;
//Information For Filter page
NSMutableArray *towns;
NSMutableArray *types;
//Shared resources to apply filters
NSDate *toDate;
NSDate *fromDate;
NSString *selectedType;
NSString *selectedTown;
//Shared resource of which button was clicked
int clicked;
int clickedCell;
int clickedContext;
}
@property (nonatomic, retain) NSMutableArray *array;
@property (nonatomic, retain) NSMutableArray *towns;
@property (nonatomic, retain) NSMutableArray *types;
@property (nonatomic) int clicked;
@property (nonatomic) int clickedCell;
@property (nonatomic) int clickedContext;
@property (nonatomic, retain) NSDate *toDate;
@property (nonatomic, retain) NSDate *fromDate;
@property (nonatomic, retain) NSString *selectedType;
@property (nonatomic, retain) NSString *selectedTown;
+(id)sharedManager;
@end
这是发生异常的函数
-(void) viewWillDisappear:(BOOL)animated
{
Helper *myHelper = [Helper sharedManager];
if(myHelper.clickedContext == 0)
{
if(myHelper.clickedCell == 0)
{
//causes exception
myHelper.fromDate = [self.fromDatePicker date];
}
else
{
//causes exception
myHelper.toDate = [self.toDatePicker date];
}
}
else
{
if(myHelper.clickedCell == 0)
{
myHelper.selectedTown = [myHelper.towns objectAtIndex:[self.townPicker selectedRowInComponent:0]];
}
else
{
myHelper.selectedType = [myHelper.types objectAtIndex:[self.typePicker selectedRowInComponent:0]];
}
}
[super viewWillDisappear:animated];
}
采摘者声明
@property (nonatomic, retain) IBOutlet UIDatePicker *toDatePicker;
@property (nonatomic, retain) IBOutlet UIDatePicker *fromDatePicker;
@property (nonatomic, retain) IBOutlet UIPickerView *typePicker;
@property (nonatomic, retain) IBOutlet UIPickerView *townPicker;
@synthesize part
@synthesize typePicker, toDatePicker, fromDatePicker, townPicker, townsView, toDateView, typesView, fromDateView;
任何想法都是为什么?
由于
答案 0 :(得分:1)
如果未在界面构建器中分配插座,则可能会发生这种情况。
如果您认为是,请尝试使用NSZombieEnabled = YES运行该应用,看看是否收到任何错误消息。
答案 1 :(得分:0)
我发现了问题。在我的帮助班里,我应该分配不保留。所以应该是
@property (nonatomic, assign) NSDate *toDate;
@property (nonatomic, assign) NSDate *fromDate;