Repository navigation
Expand file tree
/
Copy pathFGTableViewController.m
More file actions
150 lines (122 loc) · 4.15 KB
/
Copy pathFGTableViewController.m
File metadata and controls
150 lines (122 loc) · 4.15 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// FGTableViewController.m
// FastGuiKit
//
// Created by 易元 白 on 15/3/5.
// Copyright (c) 2015年 eldereal. All rights reserved.
//
#import <objc/runtime.h>
#import "FGTableViewController.h"
#import "FGInternal.h"
@interface FGTableViewController()<FGContext>
@property (copy) FGOnGuiBlock onGuiBlock;
@property (nonatomic, assign) BOOL readyForPushViewControllers;
@property (nonatomic, copy) NSString * tableViewStyleClass;
- (instancetype) initWithOnGuiBlock: (FGOnGuiBlock) block styleClass:(NSString *)styleClass;
@end
@implementation FastGui (FGTabBarController)
+ (void) tableViewController:(FGOnGuiBlock)onGui
{
[self tableViewControllerWithReuseId:[FGInternal callerPositionAsReuseId] onGui:onGui styleClass:nil];
}
+ (void)tableViewController:(FGOnGuiBlock)onGui styleClass:(NSString *)styleClass
{
[self tableViewControllerWithReuseId:[FGInternal callerPositionAsReuseId] onGui:onGui styleClass:styleClass];
}
+ (void)tableViewControllerWithReuseId: (NSString *)reuseId onGui:(FGOnGuiBlock)onGui styleClass:(NSString *)styleClass
{
[FastGui customViewControllerWithReuseId:reuseId initBlock:^UIViewController *(UIViewController *reuseCtrl) {
FGTableViewController * ctrl = (FGTableViewController *) reuseCtrl;
if (ctrl == nil){
ctrl = [[FGTableViewController alloc] initWithOnGuiBlock: onGui styleClass: styleClass];
}else{
ctrl.onGuiBlock = onGui;
}
return ctrl;
}];
}
@end
@implementation FGTableViewController
@synthesize parentContext;
@synthesize readyForPushViewControllers;
- (instancetype)initWithOnGuiBlock:(FGOnGuiBlock)block styleClass:(NSString *)styleClass
{
self.onGuiBlock = block;
self.tableViewStyleClass = styleClass;
return [super init];
}
- (void)reloadGui
{
[FastGui beginTableWithNextCustomView];
[FastGui customViewWithClass:self.tableViewStyleClass reuseId:[FGInternal memoryPositionAsReuseIdOfObject: self.tableView] initBlock:^UIView *(UIView *reuseView) {
return self.tableView;
} resultBlock:nil];
[self onGui];
[FastGui endTable];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.readyForPushViewControllers = false;
[FastGui reloadGuiSyncWithContext:self];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.readyForPushViewControllers = true;
[FastGui setRootContext: self];
[FastGui reloadGui];
}
- (void) onGui
{
if(self.onGuiBlock != nil){
@try {
self.onGuiBlock();
}
@catch (NSException *exception) {
printf("Unhandled exception: %s", [exception.description UTF8String]);
}
}
}
- (void)styleSheet
{
[parentContext styleSheet];
}
- (void)customViewControllerWithReuseId:(NSString *)reuseId initBlock:(FGInitCustomViewControllerBlock)initBlock
{
if (self.navigationController != nil){
UIViewController *ctrl = initBlock(nil);
[self.navigationController pushViewController:ctrl animated:YES];
}else if (readyForPushViewControllers){
UIViewController *ctrl = initBlock(nil);
[self presentViewController:ctrl animated:true completion:nil];
}
}
- (void)dismissViewController
{
if (self.navigationController != nil){
[self.navigationController popViewControllerAnimated:YES];
}else if (self.readyForPushViewControllers){
[self dismissViewControllerAnimated:YES completion:nil];
}
}
- (id)customViewWithReuseId:(NSString *)reuseId initBlock:(FGInitCustomViewBlock)initBlock resultBlock:(FGGetCustomViewResultBlock)resultBlock applyStyleBlock:(FGStyleBlock)applyStyleBlock
{
if ([reuseId isEqualToString:[FGInternal memoryPositionAsReuseIdOfObject:self.tableView]]) {
//add tableView to self, nothing need to do;
UITableView * table = (UITableView *) initBlock(self.tableView);
applyStyleBlock(table);
if (resultBlock == nil) {
return nil;
}else{
return resultBlock(table);
}
}
printf("Unmatched context, Do you have called to 'EndTable' without matching 'BeginTable'?\n");
return nil;
}
- (id)customData:(void *)key data:(NSDictionary *)data
{
return nil;
}
@end