Skip to content

Commit 422d99a

Browse files
committed
1) Add dynamic data source using delegate
2) Add dynamic refreshing method 3) raise version to 1.1
1 parent 8915d2f commit 422d99a

File tree

11 files changed

+490
-208
lines changed

11 files changed

+490
-208
lines changed

SCTrelloNavigation.xcodeproj/project.pbxproj

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
F068ED671BEAF1FD00C18B86 /* UINavigationBar+Awesome.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED661BEAF1FD00C18B86 /* UINavigationBar+Awesome.m */; settings = {ASSET_TAGS = (); }; };
11-
F068ED6B1BEAF77200C18B86 /* TrelloListTabView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED6A1BEAF77200C18B86 /* TrelloListTabView.m */; settings = {ASSET_TAGS = (); }; };
12-
F068ED6F1BEAF88300C18B86 /* TrelloListItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED6E1BEAF88300C18B86 /* TrelloListItem.m */; settings = {ASSET_TAGS = (); }; };
13-
F068ED721BEAF92800C18B86 /* UIViewExt.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED711BEAF92800C18B86 /* UIViewExt.m */; settings = {ASSET_TAGS = (); }; };
14-
F068ED751BEAF9D100C18B86 /* TrelloListItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED741BEAF9D100C18B86 /* TrelloListItemView.m */; settings = {ASSET_TAGS = (); }; };
15-
F068ED791BEB356100C18B86 /* TrelloListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED781BEB356100C18B86 /* TrelloListView.m */; settings = {ASSET_TAGS = (); }; };
16-
F068ED7C1BEBACA400C18B86 /* TrelloView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED7B1BEBACA400C18B86 /* TrelloView.m */; settings = {ASSET_TAGS = (); }; };
17-
F068ED7F1BEC503900C18B86 /* TrelloListTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED7E1BEC503900C18B86 /* TrelloListTableView.m */; settings = {ASSET_TAGS = (); }; };
18-
F068ED821BEC65D800C18B86 /* UIImage+ImageWithColor.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED811BEC65D800C18B86 /* UIImage+ImageWithColor.m */; settings = {ASSET_TAGS = (); }; };
19-
F068ED851BEC948800C18B86 /* TrelloListIconView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED841BEC948800C18B86 /* TrelloListIconView.m */; settings = {ASSET_TAGS = (); }; };
20-
F068ED881BECA1A700C18B86 /* TrelloListTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED871BECA1A700C18B86 /* TrelloListTableViewCell.m */; settings = {ASSET_TAGS = (); }; };
21-
F068ED8B1BECA43C00C18B86 /* TrelloListCellItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED8A1BECA43C00C18B86 /* TrelloListCellItem.m */; settings = {ASSET_TAGS = (); }; };
10+
F068ED671BEAF1FD00C18B86 /* UINavigationBar+Awesome.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED661BEAF1FD00C18B86 /* UINavigationBar+Awesome.m */; };
11+
F068ED6B1BEAF77200C18B86 /* TrelloListTabView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED6A1BEAF77200C18B86 /* TrelloListTabView.m */; };
12+
F068ED6F1BEAF88300C18B86 /* TrelloListItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED6E1BEAF88300C18B86 /* TrelloListItem.m */; };
13+
F068ED721BEAF92800C18B86 /* UIViewExt.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED711BEAF92800C18B86 /* UIViewExt.m */; };
14+
F068ED751BEAF9D100C18B86 /* TrelloListItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED741BEAF9D100C18B86 /* TrelloListItemView.m */; };
15+
F068ED791BEB356100C18B86 /* TrelloListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED781BEB356100C18B86 /* TrelloListView.m */; };
16+
F068ED7C1BEBACA400C18B86 /* TrelloView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED7B1BEBACA400C18B86 /* TrelloView.m */; };
17+
F068ED7F1BEC503900C18B86 /* TrelloListTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED7E1BEC503900C18B86 /* TrelloListTableView.m */; };
18+
F068ED821BEC65D800C18B86 /* UIImage+ImageWithColor.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED811BEC65D800C18B86 /* UIImage+ImageWithColor.m */; };
19+
F068ED851BEC948800C18B86 /* TrelloListIconView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED841BEC948800C18B86 /* TrelloListIconView.m */; };
20+
F068ED881BECA1A700C18B86 /* TrelloListTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED871BECA1A700C18B86 /* TrelloListTableViewCell.m */; };
21+
F068ED8B1BECA43C00C18B86 /* TrelloListCellItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED8A1BECA43C00C18B86 /* TrelloListCellItem.m */; };
2222
F0C932841BEAE8C2006845CF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F0C932831BEAE8C2006845CF /* main.m */; };
2323
F0C932871BEAE8C2006845CF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F0C932861BEAE8C2006845CF /* AppDelegate.m */; };
2424
F0C9328A1BEAE8C2006845CF /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0C932891BEAE8C2006845CF /* ViewController.m */; };

SCTrelloNavigation/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>1.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

SCTrelloNavigation/TrelloListTabView.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717
@property (strong,nonatomic) NSMutableArray *listItemViews;
1818
@property (nonatomic) NSInteger selectedIndex;
1919

20+
/**
21+
* 是否是缩略图模式 BOOL value to indicate whether the tab view is in brief mode or not.
22+
*/
2023
@property (nonatomic) BOOL isBriefMode;
24+
25+
/**
26+
* 是否是折叠模式 BOOL value to indicate whether the tab view is folded or not.
27+
*/
2128
@property (nonatomic) BOOL isFoldedMode;
2229

2330
@property (copy) void (^HeaderDidSwitchCallBack)();
2431

2532
- (id)initWithFrame:(CGRect)frame withListArray:(NSArray *)listItems;
2633
- (void)selectBoardAtIndex:(NSInteger)index;
34+
- (void)reloadData;
2735
@end

SCTrelloNavigation/TrelloListTabView.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ - (void)initSubViews
5555
}
5656
}
5757

58+
- (void)reloadData
59+
{
60+
self.contentSize = CGSizeMake(70.0f + self.listItems.count * 30.0f, self.height);
61+
for(TrelloListItemView *view in self.listItemViews)
62+
{
63+
[view removeFromSuperview];
64+
}
65+
[self.listItemViews removeAllObjects];
66+
67+
CGFloat nextX = 70.0f;
68+
for(TrelloListItem *t_item in self.listItems)
69+
{
70+
TrelloListItemView *view = [[TrelloListItemView alloc]initWithItem:t_item];
71+
CGRect frame = view.frame;
72+
frame.origin.x = nextX;
73+
view.frame = frame;
74+
nextX += view.width;
75+
[self addSubview:view];
76+
[self.listItemViews addObject:view];
77+
}
78+
[self selectBoardAtIndex:self.selectedIndex];
79+
}
80+
5881
- (void)selectBoardAtIndex:(NSInteger)index
5982
{
6083
[UIView animateWithDuration:0.2f animations:^{

SCTrelloNavigation/TrelloListTableView.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style listItem:(Trello
1616
if(self)
1717
{
1818
self.listItem = item;
19+
self.backgroundColor = [UIColor clearColor];
20+
self.layer.cornerRadius = 5.0f;
21+
self.layer.masksToBounds = YES;
22+
self.separatorStyle = UITableViewCellSeparatorStyleNone;
23+
self.showsHorizontalScrollIndicator = NO;
24+
self.showsVerticalScrollIndicator = NO;
1925

2026
UIView *t_view = [[UIView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, self.width, 30.0f)];
2127
t_view.backgroundColor = Global_trelloGray;

SCTrelloNavigation/TrelloListView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@
3030
@property (copy) void (^HeaderDidFoldedCallBack)();
3131

3232
- (id)initWithFrame:(CGRect)frame index:(NSInteger)index listArray:(NSArray *)listItems;
33+
- (void)reloadData;
3334
@end

SCTrelloNavigation/TrelloListView.m

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,12 @@ - (id)initWithFrame:(CGRect)frame index:(NSInteger)index listArray:(NSArray *)li
3535

3636
self.listItems = [listItems mutableCopy];
3737

38-
self.tableView = [[TrelloListTableView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, ScreenWidth - 60.0f, self.height) style:UITableViewStylePlain listItem:[listItems objectAtIndex:0]];
39-
40-
//注:这里高度加30是随便加的,高度会在往上滑动的过程中修复
41-
42-
//注:换成grouped效果也不错 = =
43-
44-
_tableView.tag = 10001;
45-
_tableView.delegate = self;
46-
_tableView.dataSource = self;
47-
_tableView.backgroundColor = [UIColor clearColor];
48-
_tableView.layer.cornerRadius = 5.0f;
49-
_tableView.layer.masksToBounds = YES;
50-
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
51-
_tableView.showsHorizontalScrollIndicator = NO;
52-
_tableView.showsVerticalScrollIndicator = NO;
53-
[self addSubview:_tableView];
54-
55-
[self.visibleTableViewArray addObject:_tableView];
56-
57-
CGFloat nextX = self.tableView.right + 15.0f;
58-
for(NSInteger i=1;i<5;i++)
38+
CGFloat nextX = 0.0f;
39+
for(NSInteger i=0;i<listItems.count;i++)
5940
{
6041
TrelloListTableView *t_tableView = [[TrelloListTableView alloc]initWithFrame:CGRectMake(nextX, 0.0f, ScreenWidth - 60.0f, self.height) style:UITableViewStylePlain listItem:[listItems objectAtIndex:i]];
61-
t_tableView.tag = 10001 + i;
6242
t_tableView.delegate = self;
6343
t_tableView.dataSource = self;
64-
t_tableView.backgroundColor = [UIColor clearColor];
65-
t_tableView.layer.cornerRadius = 5.0f;
66-
t_tableView.layer.masksToBounds = YES;
67-
t_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
68-
t_tableView.showsHorizontalScrollIndicator = NO;
69-
t_tableView.showsVerticalScrollIndicator = NO;
7044
[self addSubview:t_tableView];
7145
nextX = t_tableView.right + 15.0f;
7246

@@ -76,52 +50,83 @@ - (id)initWithFrame:(CGRect)frame index:(NSInteger)index listArray:(NSArray *)li
7650
return self;
7751
}
7852

79-
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
53+
- (void)reloadData
8054
{
81-
switch (tableView.tag) {
82-
case 10001:
55+
// still not implement reusable tableview... fuck...
56+
NSInteger currentTableViewNumber = self.visibleTableViewArray.count;
57+
if(self.listItems.count == currentTableViewNumber)
58+
{
59+
for(NSInteger i=0;i<currentTableViewNumber;i++)
8360
{
84-
return [(TrelloListTableView *)tableView listItem].rowNumber;
61+
TrelloListTableView *t_tableView = (TrelloListTableView *)[self.visibleTableViewArray objectAtIndex:i];
62+
t_tableView.listItem = [self.listItems objectAtIndex:i];
63+
[t_tableView reloadData];
8564
}
86-
break;
87-
default:
65+
}
66+
else if(self.listItems.count < currentTableViewNumber)
67+
{
68+
// if having less boards after reloading, remove the rests and reload the useful ones
69+
self.contentSize = CGSizeMake(self.listItems.count * (ScreenWidth - 45.0f), self.height);
70+
71+
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
72+
for(NSInteger i=0;i<currentTableViewNumber;i++)
73+
{
74+
if(i>=self.listItems.count)
75+
{
76+
TrelloListTableView *t_tableView = (TrelloListTableView *)[self.visibleTableViewArray objectAtIndex:i];
77+
[t_tableView removeFromSuperview];
78+
[indexSet addIndex:i];
79+
}
80+
else
81+
{
82+
TrelloListTableView *t_tableView = (TrelloListTableView *)[self.visibleTableViewArray objectAtIndex:i];
83+
t_tableView.listItem = [self.listItems objectAtIndex:i];
84+
[t_tableView reloadData];
85+
}
86+
}
87+
[self.visibleTableViewArray removeObjectsAtIndexes:indexSet];
88+
}
89+
else
90+
{
91+
self.contentSize = CGSizeMake(self.listItems.count * (ScreenWidth - 45.0f), self.height);
92+
93+
for(NSInteger i=0;i<self.listItems.count;i++)
8894
{
89-
return [(TrelloListTableView *)tableView listItem].rowNumber;
95+
CGFloat nextX = 0.0f;
96+
if(i>=currentTableViewNumber)
97+
{
98+
TrelloListTableView *t_tableView = [[TrelloListTableView alloc]initWithFrame:CGRectMake(nextX, 0.0f, ScreenWidth - 60.0f, self.height) style:UITableViewStylePlain listItem:[self.listItems objectAtIndex:i]];
99+
t_tableView.delegate = self;
100+
t_tableView.dataSource = self;
101+
[self addSubview:t_tableView];
102+
103+
nextX = t_tableView.right + 15.0f;
104+
[self.visibleTableViewArray addObject:t_tableView];
105+
}
106+
else
107+
{
108+
TrelloListTableView *t_tableView = (TrelloListTableView *)[self.visibleTableViewArray objectAtIndex:i];
109+
t_tableView.listItem = [self.listItems objectAtIndex:i];
110+
[t_tableView reloadData];
111+
nextX = t_tableView.right + 15.0f;
112+
}
90113
}
91-
break;
92114
}
93115
}
94116

117+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
118+
{
119+
return [(TrelloListTableView *)tableView listItem].rowNumber;
120+
}
121+
95122
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
96123
{
97-
switch (tableView.tag) {
98-
case 10001:
99-
{
100-
return 1;
101-
}
102-
break;
103-
default:
104-
{
105-
return 1;
106-
}
107-
break;
108-
}
124+
return 1;
109125
}
110126

111127
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
112128
{
113-
switch (tableView.tag) {
114-
case 10001:
115-
{
116-
return 60.0f;
117-
}
118-
break;
119-
default:
120-
{
121-
return 60.0f;
122-
}
123-
break;
124-
}
129+
return 60.0f;
125130
}
126131

127132
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

SCTrelloNavigation/TrelloView.h

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,116 @@
1111
#import "TrelloListTabView.h"
1212
#import "TrelloListView.h"
1313
#import "TrelloListTableView.h"
14+
#import "TrelloListCellItem.h"
15+
#import <UIKit/UIKitDefines.h>
16+
17+
@class TrelloView;
18+
19+
/**
20+
* Each board has a parameter called Level, which refers to the height of rectangle displayed in the tab view above
21+
*/
22+
typedef NS_ENUM(NSInteger, SCTrelloBoardLevel) {
23+
/**
24+
* 1x
25+
*/
26+
SCTrelloBoardLevel1 = 0,
27+
/**
28+
* 2x
29+
*/
30+
SCTrelloBoardLevel2,
31+
/**
32+
* 3x
33+
*/
34+
SCTrelloBoardLevel3,
35+
/**
36+
* 4x
37+
*/
38+
SCTrelloBoardLevel4,
39+
/**
40+
* 5x
41+
*/
42+
SCTrelloBoardLevel5
43+
};
44+
45+
@protocol TrelloDataSource <NSObject>
46+
47+
@required
48+
49+
/**
50+
* Return how many boards that you are going to display
51+
*
52+
* @param trelloView target trelloView
53+
*
54+
* @return NSInteger
55+
*/
56+
- (NSInteger)numberForBoardsInTrelloView:(TrelloView *)trelloView;
57+
58+
/**
59+
* Return how many rows each board is going to display
60+
*
61+
* @param trelloView target trelloView
62+
* @param index index of the target trelloView
63+
*
64+
* @return NSInteger
65+
*/
66+
- (NSInteger)numberForRowsInTrelloView:(TrelloView *)trelloView atBoardIndex:(NSInteger)index;
67+
68+
/**
69+
* Return the item that each row in each board is going to display.
70+
* You can extend the TrelloListCellItem model to whatever you want, just customizing your own cell in table view datasource
71+
* Enjoy yourself :)
72+
*
73+
* @param trelloView target trelloView
74+
* @param index index of the target trelloView
75+
* @param rowIndex index of the target row
76+
*
77+
* @return TrelloListCellItem
78+
*/
79+
- (TrelloListCellItem *)itemForRowsInTrelloView:(TrelloView *)trelloView atBoardIndex:(NSInteger)index atRowIndex:(NSInteger)rowIndex;
80+
81+
/**
82+
* Return title of each board
83+
*
84+
* @param trelloView target trelloView
85+
* @param index index of the target trelloView
86+
*
87+
* @return NSInteger
88+
*/
89+
- (NSString *)titleForBoardsInTrelloView:(TrelloView *)trelloView atBoardIndex:(NSInteger)index;
90+
91+
/**
92+
* Return the level of each board
93+
*
94+
* @param trelloView target trelloView
95+
* @param index index of the target trelloView
96+
*
97+
* @return SCTrelloBoardLevel
98+
*/
99+
- (SCTrelloBoardLevel)levelForRowsInTrelloView:(TrelloView *)trelloView atBoardIndex:(NSInteger)index;
100+
101+
@end
14102

15103
@interface TrelloView : UIView <UIScrollViewDelegate>
16104

17-
@property (nonatomic,strong) TrelloListTabView *tabView;
18-
@property (nonatomic,strong) TrelloListView *listView;
105+
@property (nonatomic, strong) TrelloListTabView *tabView;
106+
@property (nonatomic, strong) TrelloListView *listView;
19107
@property (nonatomic) BOOL isFoldedMode;
108+
@property (nonatomic, weak) id<TrelloDataSource> dataSource;
109+
110+
/**
111+
* Init method for newer version
112+
*
113+
* @param frame frame
114+
* @param dataSource dataSource
115+
*
116+
* @return
117+
*/
118+
- (id)initWithFrame:(CGRect)frame dataSource:(id)dataSource;
20119

21-
- (id)initWithFrame:(CGRect)frame listArray:(NSArray *)listItems;
22120
- (void)switchMode;
121+
122+
/**
123+
* Dynamic refresh data source using this method
124+
*/
125+
- (void)reloadData;
23126
@end

0 commit comments

Comments
 (0)