相关文章推荐
重感情的红茶  ·  i18Next和输入占位符·  9 月前    · 
胆小的咖啡  ·  linux 启动 ...·  1 年前    · 
精彩文章免费看

IOS 获取父类的所有子类

1、获取父类的所有子类

-(void)getSubclass

{

int numClasses;

Class *classes = NULL;

numClasses = objc_getClassList(NULL,0);

if (numClasses >0 )

{

classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numClasses);

numClasses = objc_getClassList(classes, numClasses);

for (int i = 0; i < numClasses; i++) {

if (class_getSuperclass(classes[i]) == [BaseTableViewController class]){

NSLog(@"%@===%@",classes[i], NSStringFromClass(classes[i]));

}

}

free(classes);

}

}

2、在添加页面统计等时,直接在父类实现添加方法,但是要读到子类的类名

比如在父类中添加友盟页面统计

-(void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

NSLog(@"%@",[NSString stringWithUTF8String:object_getClassName(self)]);

[MobClick beginLogPageView:[NSString stringWithUTF8String:object_getClassName(self)]];

}

-(void)viewWillDisappear:(BOOL)animated

{

[super viewWillDisappear:animated];

[MobClick endLogPageView:[NSString stringWithUTF8String:object_getClassName(self)]];

}