/ / isKindOfClassで検出されないUIButtonから継承するカスタムクラス: - ios、iphone、objective-c、uibutton

isKindOfClassで検出されないUIButtonから継承するカスタムクラス: - ios、iphone、objective-c、uibutton

私は、UIButtonから継承するいくつかの追加のプロパティを持つカスタムボタンクラスを作成しました。これは、以下のようなビューで通常のボタンで追加されます:

EFButton *btn = [EFButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(500, 100, 100, 44);
btn.backgroundColor = [UIColor lightGrayColor];
btn.userInteractionEnabled = NO;
[self.view addSubview:btn];

UIButton *nBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
nBtn.frame = CGRectMake(500, 100, 100, 44);
nBtn.backgroundColor = [UIColor lightGrayColor];
nBtn.userInteractionEnabled = NO;
[self.view addSubview:nBtn];

ビュー内のオブジェクトをループする:

  for (id view in self.view.subviews)
{

if ([view isKindOfClass:[EFButton class]])
{
//** dsnt come here **
NSLog(@"EFButton Class");
EFButton *btn = view;
}
if ([view isKindOfClass:[UIButton class]])
{
//** come here **
NSLog(@"UIButton Class");
UIButton *btn = view;
}
}

UIButtonは動作しますが、isKindOfClass:[EFButtonクラス]の状態にはなりません。私が間違ってやっていることや、やり方を教えてください。

回答:

回答№1は5

なぜなら buttonWithType のクラスメソッドです UIButton 、それは返す UIButton タイプ EFButton 継承する UIButton 、それは戻ってきません EFButton タイプ

開発者の見積もり 書類

If you subclass UIButton, this method does not return an instance of your subclass

PS:私は継承するとは思わない UIButton 良い方法です。