Search code examples
iphoneuitextfielduitextfielddelegate

block delegate methods of class in iphone


I am having a problem I am working on a class which is subclass of UITextField. Which will be used in many classes further. But I don't want to let user to use it's delegate methods in any way.

Is there any way to do this ?


Solution

  • Override setDelegate: so that it throws an exception or logs an instruction on what to do. That way your API users will know what's actually going on.

    -(void) setDelegate: (id <UITextFieldDelegate>) delegate
    {
        NSLog(@"*** Use the blocks API instead of calling %s", __PRETTY_FUNCTION__);
        [self doesNotRecognizeSelector: _cmd];
    }