【问题标题】:No visible interface for "UIView" declares the selector "setDate:Animated";“UIView”没有可见界面声明选择器“setDate:Animated”;
【发布时间】: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


【解决方案1】:

您必须将其更改为 UIDatePicker 我的建议是从情节提要中删除当前的,然后将其重新插入为 UIDatePicker 因为很可能您将其声明为 UIView

其他东西尝试弱引用你所有的IBOutlets,因为这里不需要额外的保留计数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    相关资源
    最近更新 更多