質問

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