문제

I have one UITextField, and I drag from it to its owner to set the delegate in storyboard.

And in my controller.h file, I didn't declare the class as conforming to the UITextFieldDelegate protocol.

But the - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string works! It just works!

And I wonder why?

I have met this once before when I set UITableView to a controller which does not have UITableViewDelegate and UITableViewDataSource.

도움이 되었습니까?

해결책

The methods are invoked because the delegating objects (UIWebView, UITextField, UITableView, etc.) don't check if the delegate conforms to a protocol. They are only interested in if it actually responds to a certain delegate method.

Protocol declarations, after all, are just hints for the compiler.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top