Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes a bug with selected Index in segmented cell

  • Loading branch information...
commit fb2531e3f41964782e0135a6e3bef544fea0e9af 1 parent 21afbeb
@vicpenap authored
Showing with 19 additions and 10 deletions.
  1. +19 −10 PrettyKit/Cells/PrettySegmentedControlTableViewCell.m
View
29 PrettyKit/Cells/PrettySegmentedControlTableViewCell.m
@@ -62,19 +62,28 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
self.shadowOnlyOnSelected = YES;
[self updateButtonActions];
+ [self setActionBlock:nil]; // forces tracking the selected index
}
return self;
}
-
-- (void) _setSelectedIndex:(NSInteger)sselectedIndex {
+- (void) _setSelectedIndex:(NSInteger)sselectedIndex notifySuper:(BOOL)notify
+{
selectedIndex = sselectedIndex;
- [super selectIndex:selectedIndex];
+ if (notify)
+ {
+ [super selectIndex:selectedIndex];
+ }
}
- (void) restartSelectedIndex {
- [self _setSelectedIndex:0];
+ [self _setSelectedIndex:0 notifySuper:YES];
+}
+
+
+- (void) setSelectedIndex:(NSInteger)sselectedIndex {
+ [self _setSelectedIndex:sselectedIndex notifySuper:YES];
}
@@ -91,14 +100,14 @@ - (void) setTitles:(NSArray *)titles {
}
-- (void) setSelectedIndex:(NSInteger)sselectedIndex {
- [self _setSelectedIndex:sselectedIndex];
-}
-
- (void) setActionBlock:(void (^)(NSIndexPath *indexPath, int sselectedIndex))actionBlock {
[super setActionBlock:^(NSIndexPath *indexPath, int sselectedIndex) {
- selectedIndex = sselectedIndex;
- actionBlock(indexPath, sselectedIndex);
+ [self _setSelectedIndex:sselectedIndex notifySuper:NO];
+
+ if (actionBlock)
+ {
+ actionBlock(indexPath, sselectedIndex);
+ }
}];
}
Please sign in to comment.
Something went wrong with that request. Please try again.