What does the error “unrecognized selector sent to instance” mean in Xcode

后端 未结 10 701
谎友^
谎友^ 2021-01-11 09:28

What does it mean \"unrecognized selector sent to instance\" in Xcode?

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-11 09:50

    It means, method is not defined or on the other-way, calling a method on the wrong object.

    classic example of this error is missing of ':' in selector call.

    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
                    action:@selector(DatePickerDoneClick)];
    

    Here,

    action:@selector(DatePickerDoneClick:)
    

    is expected rather than

    action:@selector(DatePickerDoneClick)
    

提交回复
热议问题