【发布时间】:2016-02-01 22:17:44
【问题描述】:
我创建了一个自定义按钮类,其中包含一些继承自 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] 的条件下。请帮助我解决我做错了什么或需要如何做。
【问题讨论】:
标签: ios iphone objective-c uibutton