oc之UIViewController的分类
@interface UIViewController (CBNib)
+ (instancetype)loadFromNib;
+ (instancetype)loadNibWithName:(NSString *)nibName;
@end
#import "UIViewController+CBNib.h"
@implementation UIViewController (CBNib)
+ (instancetype)loadFromNib {
// [self class]会由调用的类决定
return [[[self class] alloc] initWithNibName:NSStringFromClass([self class]) bundle:[NSBundle mainBundle]];
}
+ (instancetype)loadNibWithName:(NSString *)nibName{
return [[NSClassFromString(nibName) alloc] initWithNibName:nibName bundle:[NSBundle mainBundle]];
}
@end