Permalink
Browse files

Issue #1: Add a method to scroll to a column programatically.

  • Loading branch information...
1 parent 9dad7b7 commit c9dd0a4ed014c4ea0294b765e5ff45e6ca061810 @Xenofex committed Oct 27, 2011
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 459AFE9E14591A2C001AA8B6 /* NSObject+DelayedBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = 459AFE9D14591A2C001AA8B6 /* NSObject+DelayedBlock.m */; };
BB29157A13D6E76000CFA999 /* EWMultiColumnTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = BB29156E13D6E76000CFA999 /* EWMultiColumnTableView.m */; };
BB29157B13D6E76000CFA999 /* EWMultiColumnTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = BB29157013D6E76000CFA999 /* EWMultiColumnTableViewCell.m */; };
BB29157C13D6E76000CFA999 /* EWMultiColumnTableViewContentBackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = BB29157313D6E76000CFA999 /* EWMultiColumnTableViewContentBackgroundView.m */; };
@@ -26,16 +27,18 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
- BB29156D13D6E76000CFA999 /* EWMultiColumnTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; path = EWMultiColumnTableView.h; sourceTree = "<group>"; };
+ 459AFE9C14591A2C001AA8B6 /* NSObject+DelayedBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+DelayedBlock.h"; sourceTree = "<group>"; };
+ 459AFE9D14591A2C001AA8B6 /* NSObject+DelayedBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+DelayedBlock.m"; sourceTree = "<group>"; };
+ BB29156D13D6E76000CFA999 /* EWMultiColumnTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EWMultiColumnTableView.h; sourceTree = "<group>"; };
BB29156E13D6E76000CFA999 /* EWMultiColumnTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EWMultiColumnTableView.m; sourceTree = "<group>"; };
- BB29156F13D6E76000CFA999 /* EWMultiColumnTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; path = EWMultiColumnTableViewCell.h; sourceTree = "<group>"; };
+ BB29156F13D6E76000CFA999 /* EWMultiColumnTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EWMultiColumnTableViewCell.h; sourceTree = "<group>"; };
BB29157013D6E76000CFA999 /* EWMultiColumnTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EWMultiColumnTableViewCell.m; sourceTree = "<group>"; };
- BB29157113D6E76000CFA999 /* EWMultiColumnTableViewDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; path = EWMultiColumnTableViewDefaults.h; sourceTree = "<group>"; };
- BB29157213D6E76000CFA999 /* EWMultiColumnTableViewContentBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; path = EWMultiColumnTableViewContentBackgroundView.h; sourceTree = "<group>"; };
+ BB29157113D6E76000CFA999 /* EWMultiColumnTableViewDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EWMultiColumnTableViewDefaults.h; sourceTree = "<group>"; };
+ BB29157213D6E76000CFA999 /* EWMultiColumnTableViewContentBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EWMultiColumnTableViewContentBackgroundView.h; sourceTree = "<group>"; };
BB29157313D6E76000CFA999 /* EWMultiColumnTableViewContentBackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EWMultiColumnTableViewContentBackgroundView.m; sourceTree = "<group>"; };
- BB29157413D6E76000CFA999 /* EWMultiColumnTableViewBGScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; path = EWMultiColumnTableViewBGScrollView.h; sourceTree = "<group>"; };
+ BB29157413D6E76000CFA999 /* EWMultiColumnTableViewBGScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EWMultiColumnTableViewBGScrollView.h; sourceTree = "<group>"; };
BB29157513D6E76000CFA999 /* EWMultiColumnTableViewBGScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EWMultiColumnTableViewBGScrollView.m; sourceTree = "<group>"; };
- BB29157613D6E76000CFA999 /* EWHeaderHighlightLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; path = EWHeaderHighlightLayer.h; sourceTree = "<group>"; };
+ BB29157613D6E76000CFA999 /* EWHeaderHighlightLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EWHeaderHighlightLayer.h; sourceTree = "<group>"; };
BB29157713D6E76000CFA999 /* EWHeaderHighlightLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EWHeaderHighlightLayer.m; sourceTree = "<group>"; };
BB29157813D6E76000CFA999 /* UIView+AddLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+AddLine.h"; sourceTree = "<group>"; };
BB29157913D6E76000CFA999 /* UIView+AddLine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AddLine.m"; sourceTree = "<group>"; };
@@ -122,6 +125,8 @@
BBF25B1B139F20A800CE773F /* MultiColumnTableView */ = {
isa = PBXGroup;
children = (
+ 459AFE9C14591A2C001AA8B6 /* NSObject+DelayedBlock.h */,
+ 459AFE9D14591A2C001AA8B6 /* NSObject+DelayedBlock.m */,
BBF25B24139F20A800CE773F /* MultiColumnTableViewAppDelegate.h */,
BBF25B25139F20A800CE773F /* MultiColumnTableViewAppDelegate.m */,
BBF25B27139F20A800CE773F /* MainWindow.xib */,
@@ -217,6 +222,7 @@
BB29157D13D6E76000CFA999 /* EWMultiColumnTableViewBGScrollView.m in Sources */,
BB29157E13D6E76000CFA999 /* EWHeaderHighlightLayer.m in Sources */,
BB29157F13D6E76000CFA999 /* UIView+AddLine.m in Sources */,
+ 459AFE9E14591A2C001AA8B6 /* NSObject+DelayedBlock.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -29,6 +29,11 @@
@protocol EWMultiColumnTableViewDataSource;
+typedef enum __EWMultiColumnTableViewColumnPosition {
+ EWMultiColumnTableViewColumnPositionLeft,
+ EWMultiColumnTableViewColumnPositionMiddle,
+ EWMultiColumnTableViewColumnPositionRight
+} EWMultiColumnTableViewColumnPosition;
@interface EWMultiColumnTableView : UIView<UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate> {
@@ -88,6 +93,8 @@
- (void)reloadData;
- (BOOL)sectionIsFolded:(NSInteger)section;
+- (void)scrollToColumn:(NSInteger)col position:(EWMultiColumnTableViewColumnPosition)pos animated:(BOOL)animated;
+
@end
@@ -182,6 +182,8 @@ - (void)drawRect:(CGRect)rect
}
+#pragma mark - Methods
+
- (void)reloadData
{
[self reset];
@@ -197,6 +199,31 @@ - (BOOL)sectionIsFolded:(NSInteger)section
return [[sectionFoldingStatus objectAtIndex:section] boolValue];
}
+- (void)scrollToColumn:(NSInteger)col position:(EWMultiColumnTableViewColumnPosition)pos animated:(BOOL)animated
+{
+ CGFloat x = 0.0f;
+
+ for (int i = 0; i < col; i++) {
+ x += [self widthForColumn:i] + normalSeperatorLineWidth;
+ }
+
+ switch (pos) {
+ case EWMultiColumnTableViewColumnPositionMiddle:
+ x -= (scrlView.bounds.size.width - (2 * normalSeperatorLineWidth + [self widthForColumn:col])) / 2;
+ if (x < 0.0f) x = 0.0f;
+ break;
+ case EWMultiColumnTableViewColumnPositionRight:
+ x -= scrlView.bounds.size.width - (2 * normalSeperatorLineWidth + [self widthForColumn:col]);
+ if (x < 0.0f) x = 0.0f;
+ break;
+ default:
+ break;
+
+ }
+
+ [scrlView setContentOffset:CGPointMake(x, 0) animated:animated];
+}
+
#pragma mark - Properties
- (void)setDataSource:(id<EWMultiColumnTableViewDataSource>)dataSource_
@@ -290,7 +317,7 @@ - (UITableViewCell *)tblView:(UITableView *)tableView regularCellForRowAtIndexPa
if (cell == nil) {
cell = [[[EWMultiColumnTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID] autorelease];
- cell.selectionStyle = UITableViewCellEditingStyleNone;
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell addBottomLineWithWidth:normalSeperatorLineWidth color:normalSeperatorLineColor];
}
@@ -346,7 +373,7 @@ - (UITableViewCell *)tblView:(UITableView *)tableView sectionHeaderCellForRowAtI
if (cell == nil) {
cell = [[[EWMultiColumnTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID] autorelease];
- cell.selectionStyle = UITableViewCellEditingStyleNone;
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.contentView.backgroundColor = sectionHeaderBackgroundColor;
[cell addBottomLineWithWidth:normalSeperatorLineWidth color:normalSeperatorLineColor];
}
@@ -406,7 +433,7 @@ - (UITableViewCell *)headerTblView:(UITableView *)tableView cellForRowAtIndexPat
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID] autorelease];
- cell.selectionStyle = UITableViewCellEditingStyleNone;
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *headerCellView;
@@ -26,7 +26,7 @@
@class EWMultiColumnTableView;
-@interface EWMultiColumnTableViewBGScrollView : UIScrollView<UIScrollViewDelegate> {
+@interface EWMultiColumnTableViewBGScrollView : UIScrollView {
NSMutableArray *lines;
}
@@ -22,6 +22,8 @@
#import "MultiColumnTableViewViewController.h"
+#import "NSObject+DelayedBlock.h"
+
#define ROWS 100
@interface MultiColumnTableViewViewController()
@@ -137,14 +139,18 @@ - (void)viewDidLoad
tblView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:tblView];
-
+ [self performBlock:^{
+
+ [tblView scrollToColumn:3 position:EWMultiColumnTableViewColumnPositionMiddle animated:YES];
+ } afterDelay:0.5];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
+
// e.g. self.myOutlet = nil;
[tblView release];
tblView = nil;
@@ -0,0 +1,15 @@
+//
+// DelayedBlock.h
+// RenaultTraining
+//
+// Created by Eli Wang on 11-8-23.
+// Copyright 2011年 ekohe.com. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSObject (DelayedBlock)
+
+- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay;
+
+@end
@@ -0,0 +1,19 @@
+//
+// DelayedBlock.m
+// RenaultTraining
+//
+// Created by Eli Wang on 11-8-23.
+// Copyright 2011年 ekohe.com. All rights reserved.
+//
+
+#import "NSObject+DelayedBlock.h"
+
+@implementation NSObject (DelayedBlock)
+
+- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay
+{
+ int64_t delta = (int64_t)(1.0e9 * delay);
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta), dispatch_get_main_queue(), block);
+}
+
+@end

0 comments on commit c9dd0a4

Please sign in to comment.