-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoryboardReference.m
More file actions
44 lines (35 loc) · 1.45 KB
/
Copy pathStoryboardReference.m
File metadata and controls
44 lines (35 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// StoryboardReference.m
// StoryboardReference
//
// Created by rock88 on 25/06/15.
// Copyright (c) 2015 rock88. All rights reserved.
//
#import "StoryboardReference.h"
#import <objc/runtime.h>
@implementation StoryboardReference
+ (void)load
{
SEL sel = @selector(initWithIdentifier:source:destination:);
Method originMethod = class_getInstanceMethod([UIStoryboardSegue class], sel);
id(*originImpl)(id, SEL, id, id, id) = (id(*)(id, SEL, id, id, id))method_getImplementation(originMethod);
IMP impl = imp_implementationWithBlock(^id(id instance, id identifier, id source, id destination) {
StoryboardReference* reference = destination;
if ([reference isKindOfClass:[StoryboardReference class]] && reference.storyboardName.length > 0)
{
NSBundle* bundle = [NSBundle bundleForClass:self];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:reference.storyboardName bundle:bundle];
if (reference.referenceIdentifier.length > 0)
{
destination = [storyboard instantiateViewControllerWithIdentifier:reference.referenceIdentifier];
}
else
{
destination = [storyboard instantiateInitialViewController];
}
}
return originImpl(instance, sel, identifier, source, destination);
});
method_setImplementation(originMethod, impl);
}
@end