2009-08-19 11:00:06.482 Pickers[26090:20b] *** Assertion failure in -[UIDatePickerView _updateBitsForDate:andReload:animateIfNeeded:], /SourceCache/UIKit/UIKit-963.10/UIDatePicker.m:908 2009-08-19 11:00:06.483 Pickers[26090:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: date' 2009-08-19 11:00:06.484 Pickers[26090:20b] Stack: ( 807902715, 2513055291, 807986683, 811271572, 816448278, 816444436, 816445688, 10353, 815223951, 815274694, 815269866, 815277278, 9116, 814713539, 814750709, 814739251, 814722434, 814748641, 839148405, 807687520, 807683624, 814715661, 814752238, 8242 )
I keep getting that Error. I've tracked it down to the offending class, DatePickerViewController, because when I don't include that in the UITabBarController, It doesn't crash. The whole project compiles fine though. Here's DatePickerViewController:
/*
File : DatePickerViewController.m
Abstract: View Controller
project Pickers
Copyright (C) 2009 Mitchell Kember. All Rights Reserved.
*/
#import "DatePickerViewController.h"
#import "Model.h"
@implementation DatePickerViewController
@synthesize datePicker;
#pragma mark -
#pragma mark Setting up / Tearing down
- (id)init {
if((self = [super init])) {
}
return self;
}
- (void)dealloc {
[datePicker release];
[super dealloc];
}
- (void)loadView {
UIView *localView = [[UIView alloc] initWithFrame:
CGRectMake(0, 0, 320, 411)];
[localView setBackgroundColor:[UIColor whiteColor]];
[self setView:localView];
[localView release];
}
- (void)viewDidLoad {
UIDatePicker *localDatePicker = [[UIDatePicker alloc] initWithFrame:
CGRectMake(0, 0, 320, 216)];
// ======******OFFENDING LINE BELOW************=======
[localDatePicker setDate:[[Model sharedModel] dateCache] animated:NO];
/// =====**********========================*************===========
[localDatePicker addTarget:self action:@selector(datePicker_ValueChanged:)
forControlEvents:UIControlEventValueChanged];
[self setDatePicker:localDatePicker];
[localDatePicker release];
UIButton *btnSelect = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnSelect setFrame:CGRectMake(100, 298, 120, 37)];
[btnSelect setTitle:@"Select" forState:UIControlStateNormal];
[btnSelect addTarget:self action:@selector(btnSelect_Pressed:)
forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:[self datePicker]];
[[self view] addSubview:btnSelect];
[NSTimer scheduledTimerWithTimeInterval:0.3 target:self
selector:@selector(timerFireMethod:) userInfo:nil repeats:NO];
[super viewDidLoad];
}
- (void)viewDidUnload {
[self setDatePicker:nil];
[super viewDidUnload];
}
#pragma mark -
#pragma mark Timer methods
- (void)timerFireMethod:(NSTimer *)theTimer {
NSDate *now = [[NSDate alloc] init];
[[self datePicker] setDate:now animated:YES];
[now release];
[theTimer invalidate];
}
#pragma mark -
#pragma mark Control actions
- (void)datePicker_ValueChanged:(id)sender {
[[Model sharedModel] setDateCache:[[self datePicker] date]];
}
- (void)btnSelect_Pressed:(id)sender {
NSString *selected = (NSString *)[[self datePicker] date];;
NSString *msg = [[NSString alloc] initWithFormat:
@"The date and time you selected is: %@", selected];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Date and Time Selected"
message:msg
delegate:nil
cancelButtonTitle:@"Yes, I did"
otherButtonTitles:nil];
[msg release];
[alert show];
[alert release];
}
#pragma mark -
#pragma mark Memory warning
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
I'm pretty new to iPhone development. So any guesses on what I'm doing wrong? Thanks!!
EDIT: The offeding line that I pointed out in the code was causing it. I forgot to check if the value that I was trying to set the datePicker's date to was nil. And it was, so that was why it was crashing.