0
我使用uidatepicker並拋出異常,當我嘗試從日期選擇器獲取日期。uidatepicker [__NSDate date]:無法識別的選擇器發送到實例
.h文件中:
#import <UIKit/UIKit.h>
@protocol TimeDelegate <NSObject>
- (void)returnTime:(NSDate *)item;
@end
@interface TimeController : UIViewController <UIPickerViewDelegate>
{
UIDatePicker *timePicker;
}
@property (nonatomic, weak) id <TimeDelegate> delegate;
@property (nonatomic, retain) IBOutlet UIDatePicker *timePicker;
@property (nonatomic, retain) NSDate *activityTime;
@end
.m文件
#import "TimeController.h"
@implementation TimeController
@synthesize timePicker;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.timePicker = [NSDate date];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) viewDidDisappear:(BOOL)animated
{
NSLog(@"%@", self.activityTime);
//NSDate *itemToPassBack = [self.timePicker date];
[self.delegate returnTime:self.activityTime];
}
- (IBAction)SelectTime:(id)sender {
self.activityTime = [timePicker date];
}
@end
錯誤發生,當我點擊選擇或返回。最初我認爲日期選擇器在viewdiddisappear期間不可用,並拋出異常。選擇按鈕的行爲也是一樣的,這讓我懷疑還有其他的錯誤。
如果你閱讀這條消息,它會告訴你什麼是錯的。如果你不能這樣做,至少要發佈整個消息,以便我們可以告訴你什麼是錯的。 –