Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions ExpandTableViewTests/ExpandTableViewTests-Info.plist

This file was deleted.

13 changes: 0 additions & 13 deletions ExpandTableViewTests/ExpandTableViewTests.h

This file was deleted.

32 changes: 0 additions & 32 deletions ExpandTableViewTests/ExpandTableViewTests.m

This file was deleted.

2 changes: 0 additions & 2 deletions ExpandTableViewTests/en.lproj/InfoPlist.strings

This file was deleted.

440 changes: 440 additions & 0 deletions JKExpandTableView/JKExpandTableView.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NSBundle+JKExpandTableView.h
// JKExpandTableView
//
// Created by Andrey Yastrebov on 27.08.13.
// Copyright (c) 2013 Jack-Kwok. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSBundle (JKExpandTableView)

+ (NSBundle*)expandTableViewResourcesBundle;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// NSBundle+JKExpandTableView.m
// JKExpandTableView
//
// Created by Andrey Yastrebov on 27.08.13.
// Copyright (c) 2013 Jack-Kwok. All rights reserved.
//

#import "NSBundle+JKExpandTableView.h"

@implementation NSBundle (JKExpandTableView)

+ (NSBundle*)expandTableViewResourcesBundle {
static dispatch_once_t onceToken;
static NSBundle *myLibraryResourcesBundle = nil;
dispatch_once(&onceToken, ^{
myLibraryResourcesBundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"JKExpandTableViewResources" withExtension:@"bundle"]];
});
return myLibraryResourcesBundle;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UIImage+JKExpandTableView.h
// JKExpandTableView
//
// Created by Andrey Yastrebov on 27.08.13.
// Copyright (c) 2013 Jack-Kwok. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIImage (JKExpandTableView)
+ (UIImage*)expandTableViewImageNamed:(NSString*)name;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// UIImage+JKExpandTableView.m
// JKExpandTableView
//
// Created by Andrey Yastrebov on 27.08.13.
// Copyright (c) 2013 Jack-Kwok. All rights reserved.
//

#import "UIImage+JKExpandTableView.h"
#import "NSBundle+JKExpandTableView.h"

@implementation UIImage (JKExpandTableView)

+ (UIImage*)expandTableViewImageNamed:(NSString*)name {
UIImage *imageFromMainBundle = [UIImage imageNamed:name];
if (imageFromMainBundle) {
return imageFromMainBundle;
}

NSString *path = [[[NSBundle expandTableViewResourcesBundle] resourcePath] stringByAppendingPathComponent:name];

if ([path pathExtension].length == 0)
{
path = [path stringByAppendingPathExtension:@"png"];
}

UIImage *imageFromMyLibraryBundle = [UIImage imageWithContentsOfFile:path];
return imageFromMyLibraryBundle;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Prefix header for all source files of the 'JKExpandTableView' target in the 'JKExpandTableView' project
//

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@
*/
- (UIImage *) iconForCellAtChildIndex:(NSInteger) childIndex withinParentCellIndex:(NSInteger) parentIndex;

/*! Optional method

@param childIndex The child index in question
@param parentIndex The parent index in question
@return CGFloat padding for selected indicator image.
*/
- (CGFloat) selectionIconPaddingForParentIndex:(NSInteger) parentIndex;

/*! Optional method

@return YES if the parent icon should be rotated 90 degrees when parent is toggled. Otherwise, return NO.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
[cell.label setFont:font];
}

CGFloat selectionIndicatorPadding = [self.dataSourceDelegate selectionIconPaddingForParentIndex:parentIndex];
[cell setSelectionIndicatorPadding:selectionIndicatorPadding];

NSString * labelStr = [self.dataSourceDelegate labelForParentCellAtIndex:parentIndex];
[[cell label] setText:labelStr];

Expand Down Expand Up @@ -376,6 +379,15 @@ - (UIImage *) iconForChildIndex:(NSInteger)childIndex underParentIndex:(NSIntege
}
}

- (CGFloat) selectionIconPaddingForParentIndex:(NSInteger)parentIndex
{
if ([self.dataSourceDelegate respondsToSelector:@selector(selectionIconPaddingForParentIndex:)]) {
return [self.dataSourceDelegate selectionIconPaddingForParentIndex:parentIndex];
} else {
return 16.f;
}
}

- (BOOL) hasSelectedChild:(NSUInteger) parentIndex {
NSInteger numberOfChildren = [self.dataSourceDelegate numberOfChildCellsUnderParentIndex:parentIndex];
BOOL result = NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
UILabel *label;
UIImageView *selectionIndicatorImgView;
NSInteger parentIndex;
CGFloat selectionIndicatorPadding;
}

@property (nonatomic,strong) UIImageView *iconImage;
@property (nonatomic,strong) UILabel *label;
@property (nonatomic,strong) UIImage *selectionIndicatorImg;
@property (nonatomic,strong) UIImageView *selectionIndicatorImgView;
@property (nonatomic) NSInteger parentIndex;
@property (nonatomic) CGFloat selectionIndicatorPadding;

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier;
- (void)setupDisplay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
//

#import "JKParentTableViewCell.h"
#import "UIImage+JKExpandTableView.h"

@implementation JKParentTableViewCell

@synthesize label,iconImage,selectionIndicatorImgView,parentIndex,selectionIndicatorImg;
@synthesize label,iconImage,selectionIndicatorImgView,parentIndex,selectionIndicatorImg,selectionIndicatorPadding;

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier; {
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
Expand Down Expand Up @@ -65,16 +66,19 @@ - (void)setupDisplay {

CGFloat sidePadding = 6.0;
CGFloat icon2LabelPadding = 6.0;
CGFloat checkMarkPadding = 16.0;
if (selectionIndicatorPadding == 0)
{
selectionIndicatorPadding = 16.0;
}
[self.contentView setAutoresizesSubviews:YES];

self.iconImage.frame = CGRectMake(sidePadding, (contentAreaHeight - iconHeight)/2, iconWidth, iconHeight);
CGFloat XOffset = iconWidth + sidePadding + icon2LabelPadding;

CGFloat labelWidth = contentAreaWidth - XOffset - checkMarkWidth - checkMarkPadding;
CGFloat labelWidth = contentAreaWidth - XOffset - checkMarkWidth - selectionIndicatorPadding;
self.label.frame = CGRectMake(XOffset, 0, labelWidth, contentAreaHeight);
//self.label.backgroundColor = [UIColor redColor];
self.selectionIndicatorImgView.frame = CGRectMake(contentAreaWidth - checkMarkWidth - checkMarkPadding,
self.selectionIndicatorImgView.frame = CGRectMake(contentAreaWidth - checkMarkWidth - selectionIndicatorPadding,
(contentRect.size.height/2)-(checkMarkHeight/2),
checkMarkWidth,
checkMarkHeight);
Expand All @@ -97,7 +101,7 @@ - (void)rotateIconToCollapsed {
- (void)selectionIndicatorState:(BOOL) visible {
//
if (!self.selectionIndicatorImg) {
self.selectionIndicatorImg = [UIImage imageNamed:@"checkmark"];
self.selectionIndicatorImg = [UIImage expandTableViewImageNamed:@"checkmark"];
}
self.selectionIndicatorImgView.image = self.selectionIndicatorImg; // probably better to init this elsewhere
if (visible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- (NSString *) labelForChildIndex:(NSInteger)childIndex underParentIndex:(NSInteger)parentIndex;
// get the icon image
- (UIImage *) iconForChildIndex:(NSInteger)childIndex underParentIndex:(NSInteger)parentIndex;
// get padding
- (CGFloat) selectionIconPaddingForParentIndex:(NSInteger)parentIndex;
@end

@interface JKSubTableViewCell : UITableViewCell <UITableViewDataSource,UITableViewDelegate> {
Expand All @@ -33,11 +35,13 @@
UIColor *fgColor;
UIFont *font;
UIImage *selectionIndicatorImg;
CGFloat selectionIndicatorPadding;
}

@property(nonatomic,strong) UITableView *insideTableView;
@property(nonatomic,weak,getter = getDelegate, setter = setDelegate:) id<JKSubTableViewCellDelegate> delegate;
@property(nonatomic) NSInteger parentIndex;
@property(nonatomic) CGFloat selectionIndicatorPadding;
@property(nonatomic,strong) UIImage *selectionIndicatorImg;

@property(nonatomic,strong,getter = getSubTableForegroundColor, setter = setSubTableForegroundColor:) UIColor *fgColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

#import "JKSubTableViewCell.h"
#import "JKSubTableViewCellCell.h"
#import "UIImage+JKExpandTableView.h"

@implementation JKSubTableViewCell

@synthesize insideTableView, selectionIndicatorImg;
@synthesize insideTableView, selectionIndicatorImg, selectionIndicatorPadding;

#define HEIGHT_FOR_CELL 44.0

Expand Down Expand Up @@ -78,7 +79,7 @@ -(void) setSubTableFont:(UIFont *) p_font {

- (UIImage *) selectionIndicatorImgOrDefault {
if (!self.selectionIndicatorImg) {
self.selectionIndicatorImg = [UIImage imageNamed:@"checkmark"];
self.selectionIndicatorImg = [UIImage expandTableViewImageNamed:@"checkmark"];
}
return self.selectionIndicatorImg;
}
Expand Down Expand Up @@ -110,6 +111,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
NSInteger row = [indexPath row];
cell.titleLabel.text = [self.delegate labelForChildIndex:row underParentIndex:self.parentIndex];
cell.iconImage.image = [self.delegate iconForChildIndex:row underParentIndex:self.parentIndex];
cell.selectionIndicatorPadding = [self.delegate selectionIconPaddingForParentIndex:self.parentIndex];
cell.selectionIndicatorImg.image = [self selectionIndicatorImgOrDefault];

BOOL isRowSelected = [self.delegate isSelectedForChildIndex:row underParentIndex:self.parentIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
UIImageView *iconImage;
UILabel *titleLabel;
UIImageView *selectionIndicatorImg;
CGFloat selectionIndicatorPadding;
}

@property (nonatomic,strong) UIImageView *iconImage;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UIImageView *selectionIndicatorImg;
@property (nonatomic) CGFloat selectionIndicatorPadding;


- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "JKSubTableViewCellCell.h"

@implementation JKSubTableViewCellCell
@synthesize titleLabel, iconImage, selectionIndicatorImg;
@synthesize titleLabel, iconImage, selectionIndicatorImg, selectionIndicatorPadding;

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
Expand Down Expand Up @@ -63,21 +63,24 @@ - (void) setupDisplay {

CGFloat sidePadding = 22.0;
CGFloat icon2LabelPadding = 6.0;
CGFloat checkMarkPadding = 16.0;
if (selectionIndicatorPadding == 0)
{
selectionIndicatorPadding = 16.0;
}
[self.contentView setAutoresizesSubviews:YES];

self.iconImage.frame = CGRectMake(sidePadding, (contentAreaHeight - iconHeight)/2, iconWidth, iconHeight);
//self.iconImage.backgroundColor = [UIColor blueColor];

CGFloat XOffset = iconWidth + sidePadding + icon2LabelPadding;

CGFloat labelWidth = contentAreaWidth - XOffset - checkMarkWidth - checkMarkPadding;
CGFloat labelWidth = contentAreaWidth - XOffset - checkMarkWidth - selectionIndicatorPadding;
self.titleLabel.frame = CGRectMake(XOffset, 0, labelWidth, contentAreaHeight);

//self.titleLabel.backgroundColor = [UIColor purpleColor];
//self.selectionIndicatorImg.backgroundColor = [UIColor yellowColor];

self.selectionIndicatorImg.frame = CGRectMake(contentAreaWidth - checkMarkWidth - checkMarkPadding,
self.selectionIndicatorImg.frame = CGRectMake(contentAreaWidth - checkMarkWidth - selectionIndicatorPadding,
(contentRect.size.height/2)-(checkMarkHeight/2),
checkMarkWidth,
checkMarkHeight);
Expand Down
Loading