小编Has*_*eed的帖子

在isKindOfClass中未检测到从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];
Run Code Online (Sandbox Code Playgroud)

循环遍历视图中的对象,如:

  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; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uibutton ios

1
推荐指数
1
解决办法
1256
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1

uibutton ×1