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)]];
}