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

posted @ 2019-01-25 10:02  sundaysios  阅读(459)  评论(0编辑  收藏  举报