Skip to content

Commit ecf1de4

Browse files
committed
Fixes a scrolling issue and default cell label background colors on 6.1 fixes CEWendel#29 CEWendel#22
1 parent 4c689b7 commit ecf1de4

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

SWTableViewCell/SWTableViewCell.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ @implementation SWUtilityButtonTapGestureRecognizer
138138

139139
@interface SWTableViewCell () <UIScrollViewDelegate> {
140140
SWCellState _cellState; // The state of the cell within the scroll view, can be left, right or middle
141+
BOOL _isHidingUtilityButtons;
141142
CGFloat additionalRightPadding;
142143
}
143144

144145
// Scroll view to be added to UITableViewCell
145-
@property (nonatomic, weak) UIScrollView *cellScrollView;
146+
@property (nonatomic, strong) SWCellScrollView *cellScrollView;
146147

147148
// The cell's height
148149
@property (nonatomic) CGFloat height;
@@ -223,6 +224,7 @@ - (void)initializer {
223224
cellScrollView.delegate = self;
224225
cellScrollView.showsHorizontalScrollIndicator = NO;
225226
cellScrollView.scrollsToTop = NO;
227+
cellScrollView.scrollEnabled = YES;
226228

227229
UITapGestureRecognizer *tapGesutreRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewUp:)];
228230
[cellScrollView addGestureRecognizer:tapGesutreRecognizer];
@@ -407,7 +409,11 @@ - (void)leftUtilityButtonHandler:(id)sender {
407409

408410
- (void)hideUtilityButtonsAnimated:(BOOL)animated {
409411
// Scroll back to center
410-
[self.cellScrollView setContentOffset:CGPointMake([self leftUtilityButtonsWidth], 0) animated:animated];
412+
413+
// Force the scroll back to run on the main thread because of weird scroll view bugs
414+
dispatch_async(dispatch_get_main_queue(), ^{
415+
[self.cellScrollView setContentOffset:CGPointMake([self leftUtilityButtonsWidth], 0) animated:YES];
416+
});
411417
_cellState = kCellStateCenter;
412418

413419
if ([_delegate respondsToSelector:@selector(swippableTableViewCell:scrollingToState:)]) {
@@ -427,6 +433,7 @@ - (void)layoutSubviews {
427433
self.scrollViewButtonViewLeft.frame = CGRectMake([self leftUtilityButtonsWidth], 0, [self leftUtilityButtonsWidth], _height);
428434
self.scrollViewButtonViewRight.frame = CGRectMake(CGRectGetWidth(self.bounds), 0, [self rightUtilityButtonsWidth], _height);
429435
self.scrollViewContentView.frame = CGRectMake([self leftUtilityButtonsWidth], 0, CGRectGetWidth(self.bounds), _height);
436+
self.cellScrollView.scrollEnabled = YES;
430437
self.containingTableView.scrollEnabled = YES;
431438
self.tapGestureRecognizer.enabled = YES;
432439
}
@@ -552,6 +559,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
552559
self.scrollViewButtonViewLeft.frame = CGRectMake(scrollView.contentOffset.x, 0.0f, [self leftUtilityButtonsWidth], _height);
553560
}
554561
} else {
562+
self.containingTableView.scrollEnabled = YES;
555563
[scrollView setContentOffset:CGPointMake([self leftUtilityButtonsWidth], 0) animated:NO];
556564
}
557565
}
@@ -565,6 +573,7 @@ - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
565573
// Called when setContentOffset in hideUtilityButtonsAnimated: is done
566574
self.tapGestureRecognizer.enabled = YES;
567575
if (_cellState == kCellStateCenter) {
576+
self.containingTableView.scrollEnabled = YES;
568577
self.longPressGestureRecognizer.enabled = YES;
569578
}
570579
}

SWTableViewCell/ViewController.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ - (void)viewDidLoad
2828
self.tableView.dataSource = self;
2929
self.tableView.rowHeight = 90;
3030
self.tableView.allowsSelection = NO; // We essentially implement our own selection
31-
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); // Makes the horizontal row seperator stretch the entire length of the table view
31+
32+
// If you set the seperator inset on iOS 6 you get a NSInvalidArgumentException...weird
33+
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
34+
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); // Makes the horizontal row seperator stretch the entire length of the table view
35+
}
3236

3337
_sections = [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
3438

@@ -78,7 +82,6 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
7882

7983
/*
8084
This makes it so cells will not scroll sideways when the table view is scrolling.
81-
Makes scrolling the containing table view much smoother
8285
*/
8386

8487
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
@@ -128,6 +131,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
128131

129132
NSDate *dateObject = _testArray[indexPath.section][indexPath.row];
130133
cell.textLabel.text = [dateObject description];
134+
cell.textLabel.backgroundColor = [UIColor whiteColor];
135+
cell.detailTextLabel.backgroundColor = [UIColor whiteColor];
131136
cell.detailTextLabel.text = @"Some detail text";
132137

133138
// If you are setting the row height on an individual basis:
@@ -178,7 +183,7 @@ - (void)swippableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityBut
178183
NSLog(@"More button was pressed");
179184
UIAlertView *alertTest = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"More more more" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles: nil];
180185
[alertTest show];
181-
186+
182187
[cell hideUtilityButtonsAnimated:YES];
183188
break;
184189
}

0 commit comments

Comments
 (0)