Skip to content

Commit

Permalink
Updating example project to add drag-to-reorder support to the table
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian William Wolter committed Aug 4, 2011
1 parent caa7577 commit 2b977c3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ExampleProject/ConcordeExample/ExampleSectionHeaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ -(void)drawRect:(CGRect)rect {

CGContextRef g;
if((g = TUIGraphicsGetCurrentContext()) != nil){
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:g flipped:FALSE]];

CGContextSetRGBFillColor(g, 0.8, 0.8, 0.8, 1);
CGContextFillRect(g, self.bounds);
NSColor *start = [NSColor colorWithCalibratedRed:0.8 green:0.8 blue:0.8 alpha:1];
NSColor *end = [NSColor colorWithCalibratedRed:0.9 green:0.9 blue:0.9 alpha:1];
NSGradient *gradient = nil;

gradient = [[NSGradient alloc] initWithStartingColor:start endingColor:end];
[gradient drawInRect:self.bounds angle:90];
[gradient release];

[[start shadowWithLevel:0.1] set];
NSRectFill(NSMakeRect(0, 0, self.bounds.size.width, 1));

CGFloat labelHeight = 18;
self.labelRenderer.frame = CGRectMake(15, roundf((self.bounds.size.height - labelHeight) / 2.0), self.bounds.size.width - 30, labelHeight);
Expand Down
23 changes: 23 additions & 0 deletions ExampleProject/ConcordeExample/ExampleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ - (void)dealloc
- (void)tabBar:(ExampleTabBar *)tabBar didSelectTab:(NSInteger)index
{
NSLog(@"selected tab %ld", index);
if(index == [[tabBar tabViews] count] - 1){
NSLog(@"Reload table data...");
[_tableView reloadData];
}
}

- (NSInteger)numberOfSectionsInTableView:(TUITableView *)tableView
Expand Down Expand Up @@ -162,4 +166,23 @@ - (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(TUIFastIndex
}
}

-(BOOL)tableView:(TUITableView *)tableView canMoveRowAtIndexPath:(TUIFastIndexPath *)indexPath {
// return TRUE to enable row reordering by dragging; don't implement this method or return
// FALSE to disable
return TRUE;
}

-(void)tableView:(TUITableView *)tableView moveRowAtIndexPath:(TUIFastIndexPath *)fromIndexPath toIndexPath:(TUIFastIndexPath *)toIndexPath {
// update the model to reflect the changed index paths; since this example isn't backed by
// a "real" model, after dropping a cell the table will revert to it's previous state
NSLog(@"Move dragged row: %@ => %@", fromIndexPath, toIndexPath);
}

-(TUIFastIndexPath *)tableView:(TUITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(TUIFastIndexPath *)fromPath toProposedIndexPath:(TUIFastIndexPath *)proposedPath {
// optionally revise the drag-to-reorder drop target index path by returning a different index path
// than proposedPath. if proposedPath is suitable, return that. if this method is not implemented,
// proposedPath is used by default.
return proposedPath;
}

@end
6 changes: 6 additions & 0 deletions ExampleProject/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
5ED56727139DC35100031CDF /* TUIView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5ED566F2139DC35100031CDF /* TUIView.m */; };
5ED56728139DC35100031CDF /* TUIViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5ED566F4139DC35100031CDF /* TUIViewController.m */; };
5ED56736139DC35800031CDF /* CoreText+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5ED56732139DC35800031CDF /* CoreText+Additions.m */; };
D3502AAE13EA0FE4007C5CA7 /* TUITableView+Cell.m in Sources */ = {isa = PBXBuildFile; fileRef = D3502AAD13EA0FE4007C5CA7 /* TUITableView+Cell.m */; };
D3CE671313C6646B00D47B2D /* ExampleSectionHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3CE671213C6646B00D47B2D /* ExampleSectionHeaderView.m */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -178,6 +179,8 @@
5ED566F5139DC35100031CDF /* TUIViewNSViewContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIViewNSViewContainer.h; sourceTree = "<group>"; };
5ED56731139DC35800031CDF /* CoreText+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "CoreText+Additions.h"; path = "../Support/CoreText+Additions.h"; sourceTree = "<group>"; };
5ED56732139DC35800031CDF /* CoreText+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "CoreText+Additions.m"; path = "../Support/CoreText+Additions.m"; sourceTree = "<group>"; };
D3502AAC13EA0FE4007C5CA7 /* TUITableView+Cell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUITableView+Cell.h"; sourceTree = "<group>"; };
D3502AAD13EA0FE4007C5CA7 /* TUITableView+Cell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TUITableView+Cell.m"; sourceTree = "<group>"; };
D3CE671113C6646B00D47B2D /* ExampleSectionHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleSectionHeaderView.h; sourceTree = "<group>"; };
D3CE671213C6646B00D47B2D /* ExampleSectionHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleSectionHeaderView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -333,6 +336,8 @@
5ED566D0139DC35100031CDF /* TUITableView+Additions.m */,
5ED566D1139DC35100031CDF /* TUITableView+Derepeater.h */,
5ED566D2139DC35100031CDF /* TUITableView+Derepeater.m */,
D3502AAC13EA0FE4007C5CA7 /* TUITableView+Cell.h */,
D3502AAD13EA0FE4007C5CA7 /* TUITableView+Cell.m */,
5ED566D5139DC35100031CDF /* TUITableViewCell.h */,
5ED566D6139DC35100031CDF /* TUITableViewCell.m */,
5ED56698139DC35100031CDF /* TUIActivityIndicatorView.h */,
Expand Down Expand Up @@ -483,6 +488,7 @@
5C55D83713A66BD5000ED768 /* ExampleTableViewCell.m in Sources */,
5C90DB9D13A7C08E00ECDD14 /* ExampleTabBar.m in Sources */,
D3CE671313C6646B00D47B2D /* ExampleSectionHeaderView.m in Sources */,
D3502AAE13EA0FE4007C5CA7 /* TUITableView+Cell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 2b977c3

Please sign in to comment.