Permalink
Browse files

Refactor code to use NSIndexPath instead of TUIFastIndexPath

  • Loading branch information...
1 parent 6719152 commit b333d798e7b6565d63d1d33669088c7da67fc604 @jspahrsummers jspahrsummers committed Jul 28, 2012
Showing with 90 additions and 97 deletions.
  1. +9 −10 lib/UIKit/TUITableView+Cell.m
  2. +33 −35 lib/UIKit/TUITableView.h
  3. +46 −47 lib/UIKit/TUITableView.m
  4. +1 −3 lib/UIKit/TUITableViewCell.h
  5. +1 −2 lib/UIKit/TUITableViewCell.m
@@ -15,7 +15,6 @@
*/
#import "TUITableView+Cell.h"
-#import "TUIFastIndexPath.h"
// Dragged cells should be just above pinned headers
#define kTUITableViewDraggedCellZPosition 1001
@@ -122,7 +121,7 @@ -(void)__updateDraggingCell:(TUITableViewCell *)cell offset:(CGPoint)offset loca
[self beginContinuousScrollForDragAtPoint:location animated:TRUE];
TUITableViewInsertionMethod insertMethod = TUITableViewInsertionMethodAtIndex;
- TUIFastIndexPath *currentPath = nil;
+ NSIndexPath *currentPath = nil;
NSInteger sectionIndex = -1;
// determine the current index path the cell is occupying
@@ -132,13 +131,13 @@ -(void)__updateDraggingCell:(TUITableViewCell *)cell offset:(CGPoint)offset loca
// if we're on a section header (but not the first one, which can't move) which is above the origin
// index path we insert after the last index in the section above
NSInteger targetSectionIndex = sectionIndex - 1;
- currentPath = [TUIFastIndexPath indexPathForRow:[self numberOfRowsInSection:targetSectionIndex] - 1 inSection:targetSectionIndex];
+ currentPath = [NSIndexPath indexPathForRow:[self numberOfRowsInSection:targetSectionIndex] - 1 inSection:targetSectionIndex];
insertMethod = TUITableViewInsertionMethodAfterIndex;
}else{
// if we're on a section header below the origin index we insert before the first index in the
// section below
NSInteger targetSectionIndex = sectionIndex;
- currentPath = [TUIFastIndexPath indexPathForRow:0 inSection:targetSectionIndex];
+ currentPath = [NSIndexPath indexPathForRow:0 inSection:targetSectionIndex];
insertMethod = TUITableViewInsertionMethodBeforeIndex;
}
}
@@ -149,7 +148,7 @@ -(void)__updateDraggingCell:(TUITableViewCell *)cell offset:(CGPoint)offset loca
// allow the delegate to revise the proposed index path if it wants to
if(self.delegate != nil && [self.delegate respondsToSelector:@selector(tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:)]){
- TUIFastIndexPath *proposedPath = currentPath;
+ NSIndexPath *proposedPath = currentPath;
currentPath = [self.delegate tableView:self targetIndexPathForMoveFromRowAtIndexPath:cell.indexPath toProposedIndexPath:currentPath];
// revised index paths always use the "at" insertion method
switch([currentPath compare:proposedPath]){
@@ -176,8 +175,8 @@ -(void)__updateDraggingCell:(TUITableViewCell *)cell offset:(CGPoint)offset loca
NSComparisonResult currentDragDirection = (_previousDragToReorderIndexPath != nil) ? [currentPath compare:_previousDragToReorderIndexPath] : NSOrderedSame;
// ordered index paths for enumeration
- TUIFastIndexPath *fromIndexPath = nil;
- TUIFastIndexPath *toIndexPath = nil;
+ NSIndexPath *fromIndexPath = nil;
+ NSIndexPath *toIndexPath = nil;
if(currentDragDirection == NSOrderedAscending){
fromIndexPath = currentPath;
@@ -225,7 +224,7 @@ -(void)__updateDraggingCell:(TUITableViewCell *)cell offset:(CGPoint)offset loca
}
// update rows
- [self enumerateIndexPathsFromIndexPath:fromIndexPath toIndexPath:toIndexPath withOptions:0 usingBlock:^(TUIFastIndexPath *indexPath, BOOL *stop) {
+ [self enumerateIndexPathsFromIndexPath:fromIndexPath toIndexPath:toIndexPath withOptions:0 usingBlock:^(NSIndexPath *indexPath, BOOL *stop) {
TUITableViewCell *displacedCell;
if((displacedCell = [self cellForRowAtIndexPath:indexPath]) != nil && ![displacedCell isEqual:cell]){
CGRect frame = [self rectForRowAtIndexPath:indexPath];
@@ -281,7 +280,7 @@ -(void)__endDraggingCell:(TUITableViewCell *)cell offset:(CGPoint)offset locatio
// finalize drag to reorder if we have a drag index
if(_currentDragToReorderIndexPath != nil){
- TUIFastIndexPath *targetIndexPath;
+ NSIndexPath *targetIndexPath;
switch(_currentDragToReorderInsertionMethod){
case TUITableViewInsertionMethodBeforeIndex:
@@ -290,7 +289,7 @@ -(void)__endDraggingCell:(TUITableViewCell *)cell offset:(CGPoint)offset locatio
targetIndexPath = _currentDragToReorderIndexPath;
break;
case TUITableViewInsertionMethodAfterIndex:
- targetIndexPath = [TUIFastIndexPath indexPathForRow:_currentDragToReorderIndexPath.row + 1 inSection:_currentDragToReorderIndexPath.section];
+ targetIndexPath = [NSIndexPath indexPathForRow:_currentDragToReorderIndexPath.row + 1 inSection:_currentDragToReorderIndexPath.section];
break;
case TUITableViewInsertionMethodAtIndex:
default:
View
@@ -16,8 +16,6 @@
#import "TUIScrollView.h"
-@class TUIFastIndexPath;
-
typedef enum {
TUITableViewStylePlain, // regular table view
TUITableViewStyleGrouped, // grouped table view—headers stick to the top of the table view and scroll with it
@@ -44,24 +42,24 @@ typedef enum {
@protocol TUITableViewDelegate<NSObject, TUIScrollViewDelegate>
-- (CGFloat)tableView:(TUITableView *)tableView heightForRowAtIndexPath:(TUIFastIndexPath *)indexPath;
+- (CGFloat)tableView:(TUITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
@optional
-- (void)tableView:(TUITableView *)tableView willDisplayCell:(TUITableViewCell *)cell forRowAtIndexPath:(TUIFastIndexPath *)indexPath; // called after the cell's frame has been set but before it's added as a subview
-- (void)tableView:(TUITableView *)tableView didSelectRowAtIndexPath:(TUIFastIndexPath *)indexPath; // happens on left/right mouse down, key up/down
-- (void)tableView:(TUITableView *)tableView didDeselectRowAtIndexPath:(TUIFastIndexPath *)indexPath;
-- (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent *)event; // happens on left/right mouse up (can look at clickCount)
+- (void)tableView:(TUITableView *)tableView willDisplayCell:(TUITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath; // called after the cell's frame has been set but before it's added as a subview
+- (void)tableView:(TUITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; // happens on left/right mouse down, key up/down
+- (void)tableView:(TUITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
+- (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(NSIndexPath *)indexPath withEvent:(NSEvent *)event; // happens on left/right mouse up (can look at clickCount)
-- (BOOL)tableView:(TUITableView*)tableView shouldSelectRowAtIndexPath:(TUIFastIndexPath*)indexPath forEvent:(NSEvent*)event; // YES, if not implemented
-- (NSMenu *)tableView:(TUITableView *)tableView menuForRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent *)event;
+- (BOOL)tableView:(TUITableView*)tableView shouldSelectRowAtIndexPath:(NSIndexPath*)indexPath forEvent:(NSEvent*)event; // YES, if not implemented
+- (NSMenu *)tableView:(TUITableView *)tableView menuForRowAtIndexPath:(NSIndexPath *)indexPath withEvent:(NSEvent *)event;
// the following are good places to update or restore state (such as selection) when the table data reloads
- (void)tableViewWillReloadData:(TUITableView *)tableView;
- (void)tableViewDidReloadData:(TUITableView *)tableView;
// the following is optional for row reordering
-- (TUIFastIndexPath *)tableView:(TUITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(TUIFastIndexPath *)fromPath toProposedIndexPath:(TUIFastIndexPath *)proposedPath;
+- (NSIndexPath *)tableView:(TUITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)fromPath toProposedIndexPath:(NSIndexPath *)proposedPath;
@end
@@ -81,19 +79,19 @@ typedef enum {
NSMutableDictionary * _visibleItems;
NSMutableDictionary * _reusableTableCells;
- TUIFastIndexPath * _selectedIndexPath;
- TUIFastIndexPath * _indexPathShouldBeFirstResponder;
+ NSIndexPath * _selectedIndexPath;
+ NSIndexPath * _indexPathShouldBeFirstResponder;
NSInteger _futureMakeFirstResponderToken;
- TUIFastIndexPath * _keepVisibleIndexPathForReload;
+ NSIndexPath * _keepVisibleIndexPathForReload;
CGFloat _relativeOffsetForReload;
// drag-to-reorder state
TUITableViewCell * _dragToReorderCell;
CGPoint _currentDragToReorderLocation;
CGPoint _currentDragToReorderMouseOffset;
- TUIFastIndexPath * _currentDragToReorderIndexPath;
+ NSIndexPath * _currentDragToReorderIndexPath;
TUITableViewInsertionMethod _currentDragToReorderInsertionMethod;
- TUIFastIndexPath * _previousDragToReorderIndexPath;
+ NSIndexPath * _previousDragToReorderIndexPath;
TUITableViewInsertionMethod _previousDragToReorderInsertionMethod;
struct {
@@ -122,7 +120,7 @@ typedef enum {
/**
The table view itself has mechanisms for maintaining scroll position. During a live resize the table view should automatically "do the right thing". This method may be useful during a reload if you want to stay in the same spot. Use it instead of -reloadData.
*/
-- (void)reloadDataMaintainingVisibleIndexPath:(TUIFastIndexPath *)indexPath relativeOffset:(CGFloat)relativeOffset;
+- (void)reloadDataMaintainingVisibleIndexPath:(NSIndexPath *)indexPath relativeOffset:(CGFloat)relativeOffset;
// Forces a re-calculation and re-layout of the table. This is most useful for animating the relayout. It is potentially _more_ expensive than -reloadData since it has to allow for animating.
- (void)reloadLayout;
@@ -132,35 +130,35 @@ typedef enum {
- (CGRect)rectForHeaderOfSection:(NSInteger)section;
- (CGRect)rectForSection:(NSInteger)section;
-- (CGRect)rectForRowAtIndexPath:(TUIFastIndexPath *)indexPath;
+- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexSet *)indexesOfSectionsInRect:(CGRect)rect;
- (NSIndexSet *)indexesOfSectionHeadersInRect:(CGRect)rect;
-- (TUIFastIndexPath *)indexPathForCell:(TUITableViewCell *)cell; // returns nil if cell is not visible
+- (NSIndexPath *)indexPathForCell:(TUITableViewCell *)cell; // returns nil if cell is not visible
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect; // returns nil if rect not valid
-- (TUIFastIndexPath *)indexPathForRowAtPoint:(CGPoint)point;
-- (TUIFastIndexPath *)indexPathForRowAtVerticalOffset:(CGFloat)offset;
+- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;
+- (NSIndexPath *)indexPathForRowAtVerticalOffset:(CGFloat)offset;
- (NSInteger)indexOfSectionWithHeaderAtPoint:(CGPoint)point;
- (NSInteger)indexOfSectionWithHeaderAtVerticalOffset:(CGFloat)offset;
-- (void)enumerateIndexPathsUsingBlock:(void (^)(TUIFastIndexPath *indexPath, BOOL *stop))block;
-- (void)enumerateIndexPathsWithOptions:(NSEnumerationOptions)options usingBlock:(void (^)(TUIFastIndexPath *indexPath, BOOL *stop))block;
-- (void)enumerateIndexPathsFromIndexPath:(TUIFastIndexPath *)fromIndexPath toIndexPath:(TUIFastIndexPath *)toIndexPath withOptions:(NSEnumerationOptions)options usingBlock:(void (^)(TUIFastIndexPath *indexPath, BOOL *stop))block;
+- (void)enumerateIndexPathsUsingBlock:(void (^)(NSIndexPath *indexPath, BOOL *stop))block;
+- (void)enumerateIndexPathsWithOptions:(NSEnumerationOptions)options usingBlock:(void (^)(NSIndexPath *indexPath, BOOL *stop))block;
+- (void)enumerateIndexPathsFromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath withOptions:(NSEnumerationOptions)options usingBlock:(void (^)(NSIndexPath *indexPath, BOOL *stop))block;
- (TUIView *)headerViewForSection:(NSInteger)section;
-- (TUITableViewCell *)cellForRowAtIndexPath:(TUIFastIndexPath *)indexPath; // returns nil if cell is not visible or index path is out of range
+- (TUITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath; // returns nil if cell is not visible or index path is out of range
- (NSArray *)visibleCells; // no particular order
- (NSArray *)sortedVisibleCells; // top to bottom
- (NSArray *)indexPathsForVisibleRows;
-- (void)scrollToRowAtIndexPath:(TUIFastIndexPath *)indexPath atScrollPosition:(TUITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
+- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(TUITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
-- (TUIFastIndexPath *)indexPathForSelectedRow; // return nil or index path representing section and row of selection.
-- (TUIFastIndexPath *)indexPathForFirstRow;
-- (TUIFastIndexPath *)indexPathForLastRow;
+- (NSIndexPath *)indexPathForSelectedRow; // return nil or index path representing section and row of selection.
+- (NSIndexPath *)indexPathForFirstRow;
+- (NSIndexPath *)indexPathForLastRow;
-- (void)selectRowAtIndexPath:(TUIFastIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(TUITableViewScrollPosition)scrollPosition;
-- (void)deselectRowAtIndexPath:(TUIFastIndexPath *)indexPath animated:(BOOL)animated;
+- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(TUITableViewScrollPosition)scrollPosition;
+- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;
/**
Above the top cell, only visible if you pull down (if you have scroll bouncing enabled)
@@ -184,19 +182,19 @@ typedef enum {
- (NSInteger)tableView:(TUITableView *)table numberOfRowsInSection:(NSInteger)section;
-- (TUITableViewCell *)tableView:(TUITableView *)tableView cellForRowAtIndexPath:(TUIFastIndexPath *)indexPath;
+- (TUITableViewCell *)tableView:(TUITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
@optional
- (TUIView *)tableView:(TUITableView *)tableView headerViewForSection:(NSInteger)section;
// the following are required to support row reordering
-- (BOOL)tableView:(TUITableView *)tableView canMoveRowAtIndexPath:(TUIFastIndexPath *)indexPath;
-- (void)tableView:(TUITableView *)tableView moveRowAtIndexPath:(TUIFastIndexPath *)fromIndexPath toIndexPath:(TUIFastIndexPath *)toIndexPath;
+- (BOOL)tableView:(TUITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
+- (void)tableView:(TUITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath;
// the following are required to support row reordering
-- (BOOL)tableView:(TUITableView *)tableView canMoveRowAtIndexPath:(TUIFastIndexPath *)indexPath;
-- (void)tableView:(TUITableView *)tableView moveRowAtIndexPath:(TUIFastIndexPath *)fromIndexPath toIndexPath:(TUIFastIndexPath *)toIndexPath;
+- (BOOL)tableView:(TUITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
+- (void)tableView:(TUITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath;
/**
Default is 1 if not implemented
Oops, something went wrong.

0 comments on commit b333d79

Please sign in to comment.