/ / custom class наследяване от UIButton не е открит в isKindOfClass: - ios, iphone, object-c, uibutton

потребителски клас, наследяващ от UIButton, не е открит в isKindOfClass: - 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 class]. Моля, помогнете ми с това, което правя погрешно или как трябва да се направи.

Отговори:

5 за отговор № 1

Това е защото buttonWithType е клас метод на UIButton , тя се връща UIButton тип, въпреки че EFButton наследи UIButton , не може да се върне EFButton Тип

Цитирайте разработчика документи

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

PS: Аз не мисля, че наследяването UIButton е добър начин.