Skip to content

Commit

Permalink
a new layout based on column height rather than rows
Browse files Browse the repository at this point in the history
  • Loading branch information
aceisScope committed Apr 18, 2012
1 parent bc2dcf9 commit 9bfd580
Show file tree
Hide file tree
Showing 10 changed files with 646 additions and 61 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions WaterFlowDisplay.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
806B44FB1524048D00E59412 /* WaterflowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WaterflowView.h; sourceTree = "<group>"; };
806B44FC1524048D00E59412 /* WaterflowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = WaterflowView.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
806B4513152463DF00E59412 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
8081473D153E95CF00D5EEE7 /* WaterflowView(new).m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "WaterflowView(new).m"; sourceTree = "<group>"; };
8081473E153E95CF00D5EEE7 /* WaterflowView(new).h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WaterflowView(new).h"; sourceTree = "<group>"; };
8083BC961532B194008D4DF5 /* LoadingMoreFooterView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadingMoreFooterView.h; sourceTree = "<group>"; };
8083BC971532B194008D4DF5 /* LoadingMoreFooterView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoadingMoreFooterView.m; sourceTree = "<group>"; };
8083BC9F1532BF11008D4DF5 /* EGORefreshTableHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EGORefreshTableHeaderView.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -165,6 +167,8 @@
806B44E5152401EC00E59412 /* Supporting Files */,
806B44FB1524048D00E59412 /* WaterflowView.h */,
806B44FC1524048D00E59412 /* WaterflowView.m */,
8081473D153E95CF00D5EEE7 /* WaterflowView(new).m */,
8081473E153E95CF00D5EEE7 /* WaterflowView(new).h */,
);
path = WaterFlowDisplay;
sourceTree = "<group>";
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,14 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WaterFlowDisplay/WaterflowView.m"
timestampString = "355907672.44228"
timestampString = "356339440.658347"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "257"
endingLineNumber = "257"
startingLineNumber = "251"
endingLineNumber = "251"
landmarkName = "-pageScroll"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WaterFlowDisplay/ViewController.m"
timestampString = "354780202.946633"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "67"
endingLineNumber = "67"
landmarkName = "-flowView:cellForRowAtIndexPath:"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
Expand All @@ -55,19 +42,6 @@
landmarkName = "-initialize"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WaterFlowDisplay/ViewController.m"
timestampString = "354781947.13646"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "118"
endingLineNumber = "118"
landmarkName = "-flowView:heightForRowAtIndexPath:"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
Expand All @@ -86,11 +60,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WaterFlowDisplay/WaterflowView.m"
timestampString = "355907672.44228"
timestampString = "356339440.658347"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "228"
endingLineNumber = "228"
startingLineNumber = "222"
endingLineNumber = "222"
landmarkName = "-pageScroll"
landmarkType = "5">
</FileBreakpoint>
Expand All @@ -99,11 +73,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WaterFlowDisplay/WaterflowView.m"
timestampString = "355907672.44228"
timestampString = "356339440.658347"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "324"
endingLineNumber = "324"
startingLineNumber = "318"
endingLineNumber = "318"
landmarkName = "-pageScroll"
landmarkType = "5">
</FileBreakpoint>
Expand All @@ -112,11 +86,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WaterFlowDisplay/WaterflowView.m"
timestampString = "355907672.44228"
timestampString = "356339440.658347"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "315"
endingLineNumber = "315"
startingLineNumber = "309"
endingLineNumber = "309"
landmarkName = "-pageScroll"
landmarkType = "5">
</FileBreakpoint>
Expand All @@ -125,11 +99,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WaterFlowDisplay/WaterflowView.m"
timestampString = "355907672.44228"
timestampString = "356339440.658347"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "189"
endingLineNumber = "189"
startingLineNumber = "183"
endingLineNumber = "183"
landmarkName = "-reloadData"
landmarkType = "5">
</FileBreakpoint>
Expand All @@ -151,11 +125,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WaterFlowDisplay/WaterflowView.m"
timestampString = "355907672.44228"
timestampString = "356339440.658347"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "202"
endingLineNumber = "202"
startingLineNumber = "196"
endingLineNumber = "196"
landmarkName = "-reloadData"
landmarkType = "5">
</FileBreakpoint>
Expand Down
95 changes: 84 additions & 11 deletions WaterFlowDisplay/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@
#import "ViewController.h"
#import "AsyncImageView.h"

#define NUMBER_OF_COLUMNS 3

@interface ViewController ()
@property (nonatomic,retain) NSArray *imageUrls;
@property (nonatomic,retain) NSMutableArray *imageUrls;
@property (nonatomic,readwrite) int currentPage;
@end

@implementation ViewController
@synthesize imageUrls;
@synthesize imageUrls=_imageUrls;
@synthesize currentPage=_currentPage;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
count = 1;

// Do any additional setup after loading the view, typically from a nib.
flowView = [[WaterflowView alloc] initWithFrame:self.view.frame];
flowView.flowdatasource = self;
flowView.flowdelegate = self;
[self.view addSubview:flowView];


self.currentPage = 1;

self.imageUrls = [NSMutableArray array];
self.imageUrls = [NSArray arrayWithObjects:@"http://img.topit.me/l/201008/11/12815218412635.jpg",@"http://photo.l99.com/bigger/22/1284013907276_zb834a.jpg",@"http://www.webdesign.org/img_articles/7072/BW-kitten.jpg",@"http://www.raiseakitten.com/wp-content/uploads/2012/03/kitten.jpg",@"http://imagecache6.allposters.com/LRG/21/2144/C8BCD00Z.jpg",nil];

[flowView reloadData];
Expand Down Expand Up @@ -54,12 +59,41 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface

- (NSInteger)numberOfColumnsInFlowView:(WaterflowView *)flowView
{
return 3;
return NUMBER_OF_COLUMNS;
}

- (NSInteger)flowView:(WaterflowView *)flowView numberOfRowsInColumn:(NSInteger)column
{
return 6 ;
return 6;
}

- (WaterFlowCell *)flowView:(WaterflowView *)flowView_ cellForRowAtIndex:(NSInteger)index
{
static NSString *CellIdentifier = @"Cell";
WaterFlowCell *cell = [flowView_ dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil)
{
cell = [[[WaterFlowCell alloc] initWithReuseIdentifier:CellIdentifier] autorelease];

AsyncImageView *imageView = [[AsyncImageView alloc] initWithFrame:CGRectZero];
[cell addSubview:imageView];
imageView.contentMode = UIViewContentModeScaleToFill;
imageView.layer.borderColor = [[UIColor whiteColor] CGColor];
imageView.layer.borderWidth = 1;
[imageView release];
imageView.tag = 1001;
}

float height = [self flowView:nil heightForCellAtIndex:index];

AsyncImageView *imageView = (AsyncImageView *)[cell viewWithTag:1001];
imageView.frame = CGRectMake(0, 0, self.view.frame.size.width / NUMBER_OF_COLUMNS, height);

[imageView loadImage:[self.imageUrls objectAtIndex:index % 5]];

return cell;

}

- (WaterFlowCell*)flowView:(WaterflowView *)flowView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down Expand Up @@ -87,12 +121,41 @@ - (WaterFlowCell*)flowView:(WaterflowView *)flowView_ cellForRowAtIndexPath:(NSI
[imageView loadImage:[self.imageUrls objectAtIndex:(indexPath.row + indexPath.section) % 5]];

return cell;

}

#pragma mark-
#pragma mark- WaterflowDelegate

- (CGFloat)flowView:(WaterflowView *)flowView heightForCellAtIndex:(NSInteger)index
{
float height = 0;
switch (index % 5) {
case 0:
height = 127;
break;
case 1:
height = 100;
break;
case 2:
height = 87;
break;
case 3:
height = 114;
break;
case 4:
height = 140;
break;
case 5:
height = 158;
break;
default:
break;
}

return height;
}

-(CGFloat)flowView:(WaterflowView *)flowView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

Expand Down Expand Up @@ -123,12 +186,22 @@ -(CGFloat)flowView:(WaterflowView *)flowView heightForRowAtIndexPath:(NSIndexPat
height += indexPath.row + indexPath.section;

return height;

}

//- (void)flowView:(WaterflowView *)flowView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
// NSLog(@"did select at %@",indexPath);
//}

- (void)flowView:(WaterflowView *)flowView didSelectAtCell:(WaterFlowCell *)cell ForIndex:(int)index
{

}

- (void)flowView:(WaterflowView *)flowView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)flowView:(WaterflowView *)_flowView willLoadData:(int)page
{
NSLog(@"did select at %@",indexPath);
[flowView reloadData];
}

@end
71 changes: 71 additions & 0 deletions WaterFlowDisplay/WaterflowView(new).h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// WaterflowView.h
// WaterFlowDisplay
//
// Created by B.H. Liu on 12-3-29.
// Copyright (c) 2012年 Appublisher. All rights reserved.
//

#import <UIKit/UIKit.h>

@class WaterflowView;

////TableCell for WaterFlow
@interface WaterFlowCell:UIView
{
NSIndexPath *_indexPath;
NSString *_reuseIdentifier;
}

@property (nonatomic, retain) NSIndexPath *indexPath;
@property (nonatomic, retain) NSString *reuseIdentifier;

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier;

@end

////DataSource and Delegate
@protocol WaterflowViewDatasource <NSObject>
@required
- (NSInteger)numberOfColumnsInFlowView:(WaterflowView*)flowView;
- (NSInteger)flowView:(WaterflowView *)flowView numberOfRowsInColumn:(NSInteger)column;
- (WaterFlowCell *)flowView:(WaterflowView *)flowView cellForRowAtIndex:(NSInteger)index;
- (WaterFlowCell *)flowView:(WaterflowView *)flowView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
@end

@protocol WaterflowViewDelegate <NSObject>
@required
- (CGFloat)flowView:(WaterflowView *)flowView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)flowView:(WaterflowView *)flowView heightForCellAtIndex:(NSInteger)index;
@optional
- (void)flowView:(WaterflowView *)flowView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)flowView:(WaterflowView *)flowView didSelectAtCell:(WaterFlowCell*)cell ForIndex:(int)index;
- (void)flowView:(WaterflowView *)flowView willLoadData:(int)page;
@end

////Waterflow View
@interface WaterflowView : UIScrollView<UIScrollViewDelegate>
{
NSInteger numberOfColumns ;
NSInteger currentPage;

NSMutableArray *_cellHeight;
NSMutableArray *_visibleCells;
NSMutableDictionary *_reusedCells;

id <WaterflowViewDelegate> _flowdelegate;
id <WaterflowViewDatasource> _flowdatasource;
}

- (void)reloadData;

- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier;

@property (nonatomic, retain) NSMutableArray *cellHeight; //array of cells height arrays, count = numberofcolumns, and elements in each single child array represents is a total height from this cell to the top
@property (nonatomic, retain) NSMutableArray *cellIndex; //array of cells index arrays, count = numberofcolumns
@property (nonatomic, retain) NSMutableArray *visibleCells; //array of visible cell arrays, count = numberofcolumns
@property (nonatomic, retain) NSMutableDictionary *reusableCells; //key- identifier, value- array of cells
@property (nonatomic, assign) id <WaterflowViewDelegate> flowdelegate;
@property (nonatomic, assign) id <WaterflowViewDatasource> flowdatasource;

@end
Loading

0 comments on commit 9bfd580

Please sign in to comment.