- (RootViewController *)rootViewController { UIResponder *next = self.nextResponder; do { if ([next isKindOfClass:[RootViewController class]]) { return (RootViewController *)next; } next = next.nextResponder; } while (next != nil); return nil; }
+ (RootViewController *)rootViewControllerWithView:(UIView *)view { UIResponder *next = view.nextResponder; do { if ([next isKindOfClass:[RootViewController class]]) { return (RootViewController *)next; } next = next.nextResponder; } while (next != nil); return nil; }
我個人感覺,類方法用的更好一些,他只用寫在你需要的得到的實例的類中調用即可,VIew呢一般就是你的當前視圖,而且只用寫一次,在一定程度上減少了demo量