-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIViewController+JD.m
More file actions
92 lines (69 loc) · 2.18 KB
/
UIViewController+JD.m
File metadata and controls
92 lines (69 loc) · 2.18 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// UIViewController+JD.m
// AppleMusic
//
// Created by Юрий Логинов on 25.06.17.
// Copyright © 2017 Юрий Логинов. All rights reserved.
//
#import "UIViewController+JD.h"
#import "JDLoadingView.h"
#import <Masonry/Masonry.h>
#import <objc/runtime.h>
#import "JDPopup.h"
#import "JDEmptyTableView.h"
static void const *keyLoader;
static void const *keyEmptyView;
@interface UIViewController()
@property (strong, nonatomic) JDLoadingView *loader;
@property (strong, nonatomic) JDEmptyTableView *emptyView;
@end
@implementation UIViewController (JD)
- (void)setBackButtonWithTarget:(id)target action:(SEL)action {
UIImage *backImage = [UIImage imageNamed:@"arrowLeft"];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:target action:action];
}
- (void)showEmptyViewOn:(UIView *)view title:(NSString *)title {
if (self.emptyView) {
return;
}
self.emptyView = [JDEmptyTableView emptyView:title];
[view addSubview:self.emptyView];
[self.emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(view);
}];
}
- (void)hideEmptyView {
[self.emptyView removeFromSuperview];
self.emptyView = nil;
}
- (void)showLoaderOnView:(UIView *)view {
if (self.loader) {
return;
}
self.loader = [JDLoadingView view];
[view addSubview:self.loader];
[self.loader mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(view);
}];
}
- (void)hideLoader {
[self.loader removeFromSuperview];
self.loader = nil;
}
- (void)showError:(NSString *)error {
[JDPopup showPopupWithText:error];
}
#pragma mark - Getters & Setters
- (void)setLoader:(JDLoadingView *)loader {
objc_setAssociatedObject(self, &keyLoader, loader, OBJC_ASSOCIATION_RETAIN);
}
- (JDLoadingView *)loader {
return objc_getAssociatedObject(self, &keyLoader);
}
- (void)setEmptyView:(JDEmptyTableView *)emptyView {
objc_setAssociatedObject(self, &keyEmptyView, emptyView, OBJC_ASSOCIATION_RETAIN);
}
- (JDEmptyTableView *)emptyView {
return objc_getAssociatedObject(self, &keyEmptyView);
}
@end