diff --git a/quickdialog/QRadioItemElement.m b/quickdialog/QRadioItemElement.m index 3d121753..1ffb29c4 100644 --- a/quickdialog/QRadioItemElement.m +++ b/quickdialog/QRadioItemElement.m @@ -39,7 +39,13 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr UITableViewCell *cell = [super getCellForTableView:tableView controller:controller]; cell.selectionStyle = UITableViewCellSelectionStyleBlue; NSInteger selectedIndex = _radioElement==nil? _radioSection.selected : _radioElement.selected; - cell.accessoryType = selectedIndex == _index ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; + + if (selectedIndex == _index) { + [self setUpCheckmarkForCell:cell]; + } else { + [self removeCheckmarkForCell:cell]; + } + return cell; } @@ -50,11 +56,11 @@ - (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogContro if (_index != selectedIndex) { UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:indexPath.section]]; - oldCell.accessoryType = UITableViewCellAccessoryNone; + [self removeCheckmarkForCell:oldCell]; [oldCell setNeedsDisplay]; UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; - selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; + [self setUpCheckmarkForCell:selectedCell]; } if (_radioElement!= nil) @@ -81,5 +87,20 @@ - (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogContro } } +- (void)setUpCheckmarkForCell:(UITableViewCell *)cell +{ + if (_radioSection.checkmarkView != nil) { + cell.accessoryView = _radioSection.checkmarkView; + } else { + cell.accessoryType = UITableViewCellAccessoryCheckmark; + cell.accessoryView = nil; + } +} + +- (void)removeCheckmarkForCell:(UITableViewCell *)cell +{ + cell.accessoryType = UITableViewCellAccessoryNone; + cell.accessoryView = nil; +} @end \ No newline at end of file diff --git a/quickdialog/QSelectItemElement.m b/quickdialog/QSelectItemElement.m index 3f5c0bcf..f24c75a3 100644 --- a/quickdialog/QSelectItemElement.m +++ b/quickdialog/QSelectItemElement.m @@ -24,11 +24,13 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr { UITableViewCell *cell = [super getCellForTableView:tableView controller:controller]; cell.selectionStyle = UITableViewCellSelectionStyleBlue; - cell.accessoryType = - [_selectSection.selectedIndexes containsObject:[NSNumber numberWithUnsignedInteger:_index]] - ? UITableViewCellAccessoryCheckmark - : UITableViewCellAccessoryNone; - + + if ([_selectSection.selectedIndexes containsObject:[NSNumber numberWithUnsignedInteger:_index]]) { + [self setUpCheckmarkForCell:cell]; + } else { + [self removeCheckmarkForCell:cell]; + } + return cell; } @@ -42,10 +44,10 @@ - (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogContro if (_selectSection.multipleAllowed) { if ([_selectSection.selectedIndexes containsObject:numberIndex]) { - selectedCell.accessoryType = UITableViewCellAccessoryNone; + [self removeCheckmarkForCell:selectedCell]; [_selectSection.selectedIndexes removeObject:numberIndex]; } else { - selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; + [self setUpCheckmarkForCell:selectedCell]; [_selectSection.selectedIndexes addObject:numberIndex]; } } @@ -60,12 +62,12 @@ - (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogContro [NSIndexPath indexPathForRow:[oldCellRowNumber unsignedIntegerValue] inSection:indexPath.section]]; - oldCell.accessoryType = UITableViewCellAccessoryNone; + [self removeCheckmarkForCell:oldCell]; [_selectSection.selectedIndexes removeObject:oldCellRowNumber]; [oldCell setNeedsDisplay]; } - selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; + [self setUpCheckmarkForCell:selectedCell]; [_selectSection.selectedIndexes addObject:numberIndex]; } } @@ -77,4 +79,20 @@ - (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogContro [tableView deselectRowAtIndexPath:indexPath animated:YES]; } +- (void)setUpCheckmarkForCell:(UITableViewCell *)cell +{ + if (_selectSection.checkmarkView != nil) { + cell.accessoryView = _selectSection.checkmarkView; + } else { + cell.accessoryType = UITableViewCellAccessoryCheckmark; + cell.accessoryView = nil; + } +} + +- (void)removeCheckmarkForCell:(UITableViewCell *)cell +{ + cell.accessoryType = UITableViewCellAccessoryNone; + cell.accessoryView = nil; +} + @end diff --git a/quickdialog/QSelectSection.h b/quickdialog/QSelectSection.h index a7bf09d2..d745fdf7 100644 --- a/quickdialog/QSelectSection.h +++ b/quickdialog/QSelectSection.h @@ -17,6 +17,8 @@ @property (nonatomic, strong) NSMutableArray *selectedIndexes; @property (nonatomic, readonly) NSArray *selectedItems; +@property (nonatomic, retain) UIView *checkmarkView; + @property (nonatomic) BOOL multipleAllowed; @property(nonatomic, copy) void (^onSelected)(void); diff --git a/quickdialog/QSelectSection.m b/quickdialog/QSelectSection.m index 018cd71c..0713bbeb 100644 --- a/quickdialog/QSelectSection.m +++ b/quickdialog/QSelectSection.m @@ -13,7 +13,7 @@ @implementation QSelectSection @synthesize selectedIndexes = _selected; @synthesize multipleAllowed = _multipleAllowed; @synthesize onSelected = _onSelected; - +@synthesize checkmarkView = _checkmarkView; - (QSelectSection *)initWithItems:(NSArray *)stringArray selectedIndexes:(NSArray *)selected {