【发布时间】:2015-04-08 19:30:17
【问题描述】:
你能帮我找出我在这里做错了什么吗?线上的错误
[self.datePicker setDate:now animated:NO];
说
“UIView”没有可见界面声明选择器“setDate:Animated”;
上线
NSDate *selected = [self.datePicker date];
说
“UIView”没有可见界面声明选择器“日期”;
#import "BIDDatePickerViewController.h"
@interface BIDDatePickerViewController ()
@property (strong, nonatomic) IBOutlet UIView *datePicker;
@end
@implementation BIDDatePickerViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSDate *now = [NSDate date];
[self.datePicker setDate:now animated:NO];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)buttonPressed:(id)sender {
NSDate *selected = [self.datePicker date];
NSString *message = [[NSString alloc] initWithFormat: @"The date and time you selected is %@", selected];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Date and time selected"
message: message
delegate: nil
cancelButtonTitle: @"That's so true!"
otherButtonTitles: nil];
[alert show];
}
@end
更新
尝试将 UIView 更改为 UIDatePicker,现在它可以构建但崩溃了
2015-04-08 22:37:26.211 Pckers[3317:211755] -[UIView setDate:animated:]:
unrecognized selector sent to instance 0x7faa32f26b90
2015-04-08 22:37:26.215 Pckers[3317:211755] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-[UIView
setDate:animated:]: unrecognized selector sent to instance 0x7faa32f26b90'
*** First throw call stack:
【问题讨论】:
-
将您的
datePicker属性更改为UIDatePicker而不是UIView。 -
现在它崩溃了 ' 2015-04-08 22:33:36.440 Pckers[3231:207204] -[UIView setDate:animated:]: unrecognized selector sent to instance 0x7fda82f560b0 2015-04-08 22 :33:36.448 Pckers [3231:207204] ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UIView setDate:animated:]:无法识别的选择器发送到实例0x7fda82f560b0''
-
您是否真的将
UIDatePicker分配给您的datePicker出口?听起来您已经分配了一个普通的旧UIView。 -
重新检查,重新连接,它有所帮助。非常感谢!
标签: ios objective-c