Skip to content

Commit

Permalink
1) Add dynamic data source using delegate
Browse files Browse the repository at this point in the history
2) Add dynamic refreshing method
3) raise version to 1.1
  • Loading branch information
SergioChan committed Nov 12, 2015
1 parent 8915d2f commit 422d99a
Show file tree
Hide file tree
Showing 11 changed files with 490 additions and 208 deletions.
24 changes: 12 additions & 12 deletions SCTrelloNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
objects = {

/* Begin PBXBuildFile section */
F068ED671BEAF1FD00C18B86 /* UINavigationBar+Awesome.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED661BEAF1FD00C18B86 /* UINavigationBar+Awesome.m */; settings = {ASSET_TAGS = (); }; };
F068ED6B1BEAF77200C18B86 /* TrelloListTabView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED6A1BEAF77200C18B86 /* TrelloListTabView.m */; settings = {ASSET_TAGS = (); }; };
F068ED6F1BEAF88300C18B86 /* TrelloListItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED6E1BEAF88300C18B86 /* TrelloListItem.m */; settings = {ASSET_TAGS = (); }; };
F068ED721BEAF92800C18B86 /* UIViewExt.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED711BEAF92800C18B86 /* UIViewExt.m */; settings = {ASSET_TAGS = (); }; };
F068ED751BEAF9D100C18B86 /* TrelloListItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED741BEAF9D100C18B86 /* TrelloListItemView.m */; settings = {ASSET_TAGS = (); }; };
F068ED791BEB356100C18B86 /* TrelloListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED781BEB356100C18B86 /* TrelloListView.m */; settings = {ASSET_TAGS = (); }; };
F068ED7C1BEBACA400C18B86 /* TrelloView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED7B1BEBACA400C18B86 /* TrelloView.m */; settings = {ASSET_TAGS = (); }; };
F068ED7F1BEC503900C18B86 /* TrelloListTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED7E1BEC503900C18B86 /* TrelloListTableView.m */; settings = {ASSET_TAGS = (); }; };
F068ED821BEC65D800C18B86 /* UIImage+ImageWithColor.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED811BEC65D800C18B86 /* UIImage+ImageWithColor.m */; settings = {ASSET_TAGS = (); }; };
F068ED851BEC948800C18B86 /* TrelloListIconView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED841BEC948800C18B86 /* TrelloListIconView.m */; settings = {ASSET_TAGS = (); }; };
F068ED881BECA1A700C18B86 /* TrelloListTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED871BECA1A700C18B86 /* TrelloListTableViewCell.m */; settings = {ASSET_TAGS = (); }; };
F068ED8B1BECA43C00C18B86 /* TrelloListCellItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED8A1BECA43C00C18B86 /* TrelloListCellItem.m */; settings = {ASSET_TAGS = (); }; };
F068ED671BEAF1FD00C18B86 /* UINavigationBar+Awesome.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED661BEAF1FD00C18B86 /* UINavigationBar+Awesome.m */; };
F068ED6B1BEAF77200C18B86 /* TrelloListTabView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED6A1BEAF77200C18B86 /* TrelloListTabView.m */; };
F068ED6F1BEAF88300C18B86 /* TrelloListItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED6E1BEAF88300C18B86 /* TrelloListItem.m */; };
F068ED721BEAF92800C18B86 /* UIViewExt.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED711BEAF92800C18B86 /* UIViewExt.m */; };
F068ED751BEAF9D100C18B86 /* TrelloListItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED741BEAF9D100C18B86 /* TrelloListItemView.m */; };
F068ED791BEB356100C18B86 /* TrelloListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED781BEB356100C18B86 /* TrelloListView.m */; };
F068ED7C1BEBACA400C18B86 /* TrelloView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED7B1BEBACA400C18B86 /* TrelloView.m */; };
F068ED7F1BEC503900C18B86 /* TrelloListTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED7E1BEC503900C18B86 /* TrelloListTableView.m */; };
F068ED821BEC65D800C18B86 /* UIImage+ImageWithColor.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED811BEC65D800C18B86 /* UIImage+ImageWithColor.m */; };
F068ED851BEC948800C18B86 /* TrelloListIconView.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED841BEC948800C18B86 /* TrelloListIconView.m */; };
F068ED881BECA1A700C18B86 /* TrelloListTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED871BECA1A700C18B86 /* TrelloListTableViewCell.m */; };
F068ED8B1BECA43C00C18B86 /* TrelloListCellItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F068ED8A1BECA43C00C18B86 /* TrelloListCellItem.m */; };
F0C932841BEAE8C2006845CF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F0C932831BEAE8C2006845CF /* main.m */; };
F0C932871BEAE8C2006845CF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F0C932861BEAE8C2006845CF /* AppDelegate.m */; };
F0C9328A1BEAE8C2006845CF /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0C932891BEAE8C2006845CF /* ViewController.m */; };
Expand Down
2 changes: 1 addition & 1 deletion SCTrelloNavigation/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
8 changes: 8 additions & 0 deletions SCTrelloNavigation/TrelloListTabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@
@property (strong,nonatomic) NSMutableArray *listItemViews;
@property (nonatomic) NSInteger selectedIndex;

/**
* 是否是缩略图模式 BOOL value to indicate whether the tab view is in brief mode or not.
*/
@property (nonatomic) BOOL isBriefMode;

/**
* 是否是折叠模式 BOOL value to indicate whether the tab view is folded or not.
*/
@property (nonatomic) BOOL isFoldedMode;

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

- (id)initWithFrame:(CGRect)frame withListArray:(NSArray *)listItems;
- (void)selectBoardAtIndex:(NSInteger)index;
- (void)reloadData;
@end
23 changes: 23 additions & 0 deletions SCTrelloNavigation/TrelloListTabView.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ - (void)initSubViews
}
}

- (void)reloadData
{
self.contentSize = CGSizeMake(70.0f + self.listItems.count * 30.0f, self.height);
for(TrelloListItemView *view in self.listItemViews)
{
[view removeFromSuperview];
}
[self.listItemViews removeAllObjects];

CGFloat nextX = 70.0f;
for(TrelloListItem *t_item in self.listItems)
{
TrelloListItemView *view = [[TrelloListItemView alloc]initWithItem:t_item];
CGRect frame = view.frame;
frame.origin.x = nextX;
view.frame = frame;
nextX += view.width;
[self addSubview:view];
[self.listItemViews addObject:view];
}
[self selectBoardAtIndex:self.selectedIndex];
}

- (void)selectBoardAtIndex:(NSInteger)index
{
[UIView animateWithDuration:0.2f animations:^{
Expand Down
6 changes: 6 additions & 0 deletions SCTrelloNavigation/TrelloListTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style listItem:(Trello
if(self)
{
self.listItem = item;
self.backgroundColor = [UIColor clearColor];
self.layer.cornerRadius = 5.0f;
self.layer.masksToBounds = YES;
self.separatorStyle = UITableViewCellSeparatorStyleNone;
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;

UIView *t_view = [[UIView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, self.width, 30.0f)];
t_view.backgroundColor = Global_trelloGray;
Expand Down
1 change: 1 addition & 0 deletions SCTrelloNavigation/TrelloListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
@property (copy) void (^HeaderDidFoldedCallBack)();

- (id)initWithFrame:(CGRect)frame index:(NSInteger)index listArray:(NSArray *)listItems;
- (void)reloadData;
@end
125 changes: 65 additions & 60 deletions SCTrelloNavigation/TrelloListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,12 @@ - (id)initWithFrame:(CGRect)frame index:(NSInteger)index listArray:(NSArray *)li

self.listItems = [listItems mutableCopy];

self.tableView = [[TrelloListTableView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, ScreenWidth - 60.0f, self.height) style:UITableViewStylePlain listItem:[listItems objectAtIndex:0]];

//注:这里高度加30是随便加的,高度会在往上滑动的过程中修复

//注:换成grouped效果也不错 = =

_tableView.tag = 10001;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.layer.cornerRadius = 5.0f;
_tableView.layer.masksToBounds = YES;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.showsHorizontalScrollIndicator = NO;
_tableView.showsVerticalScrollIndicator = NO;
[self addSubview:_tableView];

[self.visibleTableViewArray addObject:_tableView];

CGFloat nextX = self.tableView.right + 15.0f;
for(NSInteger i=1;i<5;i++)
CGFloat nextX = 0.0f;
for(NSInteger i=0;i<listItems.count;i++)
{
TrelloListTableView *t_tableView = [[TrelloListTableView alloc]initWithFrame:CGRectMake(nextX, 0.0f, ScreenWidth - 60.0f, self.height) style:UITableViewStylePlain listItem:[listItems objectAtIndex:i]];
t_tableView.tag = 10001 + i;
t_tableView.delegate = self;
t_tableView.dataSource = self;
t_tableView.backgroundColor = [UIColor clearColor];
t_tableView.layer.cornerRadius = 5.0f;
t_tableView.layer.masksToBounds = YES;
t_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
t_tableView.showsHorizontalScrollIndicator = NO;
t_tableView.showsVerticalScrollIndicator = NO;
[self addSubview:t_tableView];
nextX = t_tableView.right + 15.0f;

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (void)reloadData
{
switch (tableView.tag) {
case 10001:
// still not implement reusable tableview... fuck...
NSInteger currentTableViewNumber = self.visibleTableViewArray.count;
if(self.listItems.count == currentTableViewNumber)
{
for(NSInteger i=0;i<currentTableViewNumber;i++)
{
return [(TrelloListTableView *)tableView listItem].rowNumber;
TrelloListTableView *t_tableView = (TrelloListTableView *)[self.visibleTableViewArray objectAtIndex:i];
t_tableView.listItem = [self.listItems objectAtIndex:i];
[t_tableView reloadData];
}
break;
default:
}
else if(self.listItems.count < currentTableViewNumber)
{
// if having less boards after reloading, remove the rests and reload the useful ones
self.contentSize = CGSizeMake(self.listItems.count * (ScreenWidth - 45.0f), self.height);

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
for(NSInteger i=0;i<currentTableViewNumber;i++)
{
if(i>=self.listItems.count)
{
TrelloListTableView *t_tableView = (TrelloListTableView *)[self.visibleTableViewArray objectAtIndex:i];
[t_tableView removeFromSuperview];
[indexSet addIndex:i];
}
else
{
TrelloListTableView *t_tableView = (TrelloListTableView *)[self.visibleTableViewArray objectAtIndex:i];
t_tableView.listItem = [self.listItems objectAtIndex:i];
[t_tableView reloadData];
}
}
[self.visibleTableViewArray removeObjectsAtIndexes:indexSet];
}
else
{
self.contentSize = CGSizeMake(self.listItems.count * (ScreenWidth - 45.0f), self.height);

for(NSInteger i=0;i<self.listItems.count;i++)
{
return [(TrelloListTableView *)tableView listItem].rowNumber;
CGFloat nextX = 0.0f;
if(i>=currentTableViewNumber)
{
TrelloListTableView *t_tableView = [[TrelloListTableView alloc]initWithFrame:CGRectMake(nextX, 0.0f, ScreenWidth - 60.0f, self.height) style:UITableViewStylePlain listItem:[self.listItems objectAtIndex:i]];
t_tableView.delegate = self;
t_tableView.dataSource = self;
[self addSubview:t_tableView];

nextX = t_tableView.right + 15.0f;
[self.visibleTableViewArray addObject:t_tableView];
}
else
{
TrelloListTableView *t_tableView = (TrelloListTableView *)[self.visibleTableViewArray objectAtIndex:i];
t_tableView.listItem = [self.listItems objectAtIndex:i];
[t_tableView reloadData];
nextX = t_tableView.right + 15.0f;
}
}
break;
}
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [(TrelloListTableView *)tableView listItem].rowNumber;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
switch (tableView.tag) {
case 10001:
{
return 1;
}
break;
default:
{
return 1;
}
break;
}
return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
switch (tableView.tag) {
case 10001:
{
return 60.0f;
}
break;
default:
{
return 60.0f;
}
break;
}
return 60.0f;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Expand Down
109 changes: 106 additions & 3 deletions SCTrelloNavigation/TrelloView.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,116 @@
#import "TrelloListTabView.h"
#import "TrelloListView.h"
#import "TrelloListTableView.h"
#import "TrelloListCellItem.h"
#import <UIKit/UIKitDefines.h>

@class TrelloView;

/**
* Each board has a parameter called Level, which refers to the height of rectangle displayed in the tab view above
*/
typedef NS_ENUM(NSInteger, SCTrelloBoardLevel) {
/**
* 1x
*/
SCTrelloBoardLevel1 = 0,
/**
* 2x
*/
SCTrelloBoardLevel2,
/**
* 3x
*/
SCTrelloBoardLevel3,
/**
* 4x
*/
SCTrelloBoardLevel4,
/**
* 5x
*/
SCTrelloBoardLevel5
};

@protocol TrelloDataSource <NSObject>

@required

/**
* Return how many boards that you are going to display
*
* @param trelloView target trelloView
*
* @return NSInteger
*/
- (NSInteger)numberForBoardsInTrelloView:(TrelloView *)trelloView;

/**
* Return how many rows each board is going to display
*
* @param trelloView target trelloView
* @param index index of the target trelloView
*
* @return NSInteger
*/
- (NSInteger)numberForRowsInTrelloView:(TrelloView *)trelloView atBoardIndex:(NSInteger)index;

/**
* Return the item that each row in each board is going to display.
* You can extend the TrelloListCellItem model to whatever you want, just customizing your own cell in table view datasource
* Enjoy yourself :)
*
* @param trelloView target trelloView
* @param index index of the target trelloView
* @param rowIndex index of the target row
*
* @return TrelloListCellItem
*/
- (TrelloListCellItem *)itemForRowsInTrelloView:(TrelloView *)trelloView atBoardIndex:(NSInteger)index atRowIndex:(NSInteger)rowIndex;

/**
* Return title of each board
*
* @param trelloView target trelloView
* @param index index of the target trelloView
*
* @return NSInteger
*/
- (NSString *)titleForBoardsInTrelloView:(TrelloView *)trelloView atBoardIndex:(NSInteger)index;

/**
* Return the level of each board
*
* @param trelloView target trelloView
* @param index index of the target trelloView
*
* @return SCTrelloBoardLevel
*/
- (SCTrelloBoardLevel)levelForRowsInTrelloView:(TrelloView *)trelloView atBoardIndex:(NSInteger)index;

@end

@interface TrelloView : UIView <UIScrollViewDelegate>

@property (nonatomic,strong) TrelloListTabView *tabView;
@property (nonatomic,strong) TrelloListView *listView;
@property (nonatomic, strong) TrelloListTabView *tabView;
@property (nonatomic, strong) TrelloListView *listView;
@property (nonatomic) BOOL isFoldedMode;
@property (nonatomic, weak) id<TrelloDataSource> dataSource;

/**
* Init method for newer version
*
* @param frame frame
* @param dataSource dataSource
*
* @return
*/
- (id)initWithFrame:(CGRect)frame dataSource:(id)dataSource;

- (id)initWithFrame:(CGRect)frame listArray:(NSArray *)listItems;
- (void)switchMode;

/**
* Dynamic refresh data source using this method
*/
- (void)reloadData;
@end
Loading

0 comments on commit 422d99a

Please sign in to comment.