Subclassing UIButton but can't access my properties

后端 未结 4 1873
夕颜
夕颜 2020-12-16 08:51

I\'ve created a sub class of UIButton:

//
//  DetailButton.h
#import 
#import 

@interface MyDetailButt         


        
4条回答
  •  死守一世寂寞
    2020-12-16 09:07

    Just making a subclass isn't enough; the subclass does not take the place of its superclass. The same way not all UIControls, not all UIViews, not all UIResponders, and not all NSObjects have the behavior of UIButton, not all UIButtons have the behavior of your custom subclass.

    What you need is an instance of your subclass. What you have is an instance of UIButton.

    The solution is to make that instance an instance of your subclass instead. If you created the button in Interface Builder, select the button and press ⌘6, then change the instance's Custom Class there. If you're creating the button in code, send your alloc message to your custom subclass, not directly to UIButton.

提交回复
热议问题