Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit c9f69dc4feaa82020a90cccdad4579c4a041b015 0 parents
@jakemarsh authored
18 .gitignore
@@ -0,0 +1,18 @@
+.DS_Store
+_Design
+_Web
+# Xcode
+build/*
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+*.xcworkspace
+!default.xcworkspace
+xcuserdata
+profile
+*.moved-aside
13 JMStaticContentTableViewController.podspec
@@ -0,0 +1,13 @@
+Pod::Spec.new do |s|
+ s.name = 'JMStaticContentTableViewController'
+ s.version = '0.0.1'
+ s.license = 'MIT'
+ s.summary = 'A subclass-able way to cleanly and neatly implement a table view controller much like those in Settings.app, with nice-looking fields to collect or display information.'
+ s.homepage = 'https://github.com/jakemarsh/JMStaticContentTableViewController'
+ s.authors = { 'Jake Marsh' => 'jake@deallocatedobjects.com' }
+ s.source = { :git => 'git://github.com/jakemarsh/JMStaticContentTableViewController.git', :tag => '0.0.1' }
+
+ s.platform = :ios
+
+ s.source_files = ['JMStaticContentTableViewController/JMStaticContentTableViewBlocks.h', 'JMStaticContentTableViewController/JMStaticContentTableViewController.*', 'JMStaticContentTableViewController/JMStaticContentTableViewSection.*', 'JMStaticContentTableViewController/JMStaticContentTableViewCell.*', 'JMStaticContentTableViewController/StaticTextFieldTableViewCell.*']
+end
16 JMStaticContentTableViewController/JMStaticContentTableViewBlocks.h
@@ -0,0 +1,16 @@
+//
+// JMStaticContentTableView.h
+// JMStaticTableViewController
+//
+// Created by Jake Marsh on 10/8/11.
+// Copyright (c) 2011 Rubber Duck Software. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class JMStaticContentTableViewSection, JMStaticContentTableViewCell;
+
+typedef void(^JMStaticContentTableViewCellBlock)(JMStaticContentTableViewCell *staticContentCell, UITableViewCell *cell, NSIndexPath *indexPath);
+typedef void(^JMStaticContentTableViewCellWhenSelectedBlock)(NSIndexPath *indexPath);
+
+typedef void(^JMStaticContentTableViewControllerAddSectionBlock)(JMStaticContentTableViewSection *section, NSUInteger sectionIndex);
14 JMStaticContentTableViewController/JMStaticContentTableViewCell.h
@@ -0,0 +1,14 @@
+#import <Foundation/Foundation.h>
+#import "JMStaticContentTableViewBlocks.h"
+
+@interface JMStaticContentTableViewCell : NSObject
+
+@property (nonatomic, retain) NSString *reuseIdentifier;
+@property (nonatomic) CGFloat cellHeight;
+@property (nonatomic) UITableViewCellStyle cellStyle;
+@property (nonatomic, retain) Class tableViewCellSubclass;
+
+@property (nonatomic, copy) JMStaticContentTableViewCellBlock configureBlock;
+@property (nonatomic, copy) JMStaticContentTableViewCellWhenSelectedBlock whenSelectedBlock;
+
+@end
34 JMStaticContentTableViewController/JMStaticContentTableViewCell.m
@@ -0,0 +1,34 @@
+#import "JMStaticContentTableViewCell.h"
+
+@implementation JMStaticContentTableViewCell
+
+@synthesize reuseIdentifier = _reuseIdentifier;
+@synthesize cellHeight = _cellHeight;
+@synthesize cellStyle = _cellStyle;
+@synthesize tableViewCellSubclass = _tableViewCellSubclass;
+
+@synthesize configureBlock = _configureBlock;
+@synthesize whenSelectedBlock = _whenSelectedBlock;
+
+- (id) init {
+ self = [super init];
+ if(!self) return nil;
+
+ self.cellHeight = UITableViewAutomaticDimension;
+ self.tableViewCellSubclass = [UITableViewCell class];
+ self.cellStyle = UITableViewCellStyleDefault;
+ self.reuseIdentifier = @"DefaultCell";
+
+ return self;
+}
+- (void) dealloc {
+ [_reuseIdentifier release];
+ [_tableViewCellSubclass release];
+
+ [_configureBlock release];
+ [_whenSelectedBlock release];
+
+ [super dealloc];
+}
+
+@end
37 JMStaticContentTableViewController/JMStaticContentTableViewController.h
@@ -0,0 +1,37 @@
+#import <UIKit/UIKit.h>
+#import "JMStaticContentTableViewSection.h"
+#import "JMStaticContentTableViewCell.h"
+#import "StaticTextFieldTableViewCell.h"
+#import "JMStaticContentTableViewBlocks.h"
+
+@interface JMStaticContentTableViewController : UITableViewController
+
+@property (nonatomic, retain) NSArray *staticContentSections;
+@property (nonatomic, retain) NSString *footerText;
+
+- (void) addSection:(JMStaticContentTableViewControllerAddSectionBlock)b;
+
+- (void) insertSection:(JMStaticContentTableViewControllerAddSectionBlock)b
+ atIndex:(NSUInteger)sectionIndex;
+
+- (void) insertSection:(JMStaticContentTableViewControllerAddSectionBlock)b
+ atIndex:(NSUInteger)sectionIndex
+ animated:(BOOL)animated;
+
+- (void) removeAllSections;
+
+- (void) removeSectionAtIndex:(NSUInteger)sectionIndex;
+- (void) removeSectionAtIndex:(NSUInteger)sectionIndex animated:(BOOL)animated;
+
+- (JMStaticContentTableViewSection *) sectionAtIndex:(NSUInteger)sectionIndex;
+
+- (void) insertCell:(JMStaticContentTableViewCellBlock)configurationBlock
+ atIndexPath:(NSIndexPath *)indexPath
+ animated:(BOOL)animated;
+
+- (void) insertCell:(JMStaticContentTableViewCellBlock)configurationBlock
+ whenSelected:(JMStaticContentTableViewCellWhenSelectedBlock)whenSelectedBlock
+ atIndexPath:(NSIndexPath *)indexPath
+ animated:(BOOL)animated;
+
+@end
242 JMStaticContentTableViewController/JMStaticContentTableViewController.m
@@ -0,0 +1,242 @@
+#import "JMStaticContentTableViewController.h"
+#import <QuartzCore/QuartzCore.h>
+
+@implementation JMStaticContentTableViewController
+
+@synthesize staticContentSections = _staticContentSections;
+@synthesize footerText = _footerText;
+
+- (void) dealloc {
+ [_staticContentSections release];
+ [_footerText release];
+
+ [super dealloc];
+}
+- (void) didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+}
+
+#pragma mark - View lifecycle
+
+- (void) viewDidLoad {
+ [super viewDidLoad];
+
+ [self removeAllSections];
+}
+- (void) viewDidUnload {
+ [super viewDidUnload];
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
+ return self.staticContentSections.count;
+}
+- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ JMStaticContentTableViewSection *sectionContent = [self.staticContentSections objectAtIndex:section];
+
+ return sectionContent.staticContentCells.count;
+}
+
+- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+ JMStaticContentTableViewSection *sectionContent = [self.staticContentSections objectAtIndex:indexPath.section];
+ JMStaticContentTableViewCell *cellContent = [sectionContent.staticContentCells objectAtIndex:indexPath.row];
+
+ return cellContent.cellHeight;
+}
+- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
+ JMStaticContentTableViewSection *sectionContent = [self.staticContentSections objectAtIndex:section];
+ return sectionContent.title;
+}
+
+- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ JMStaticContentTableViewSection *sectionContent = [self.staticContentSections objectAtIndex:indexPath.section];
+ JMStaticContentTableViewCell *cellContent = [sectionContent.staticContentCells objectAtIndex:indexPath.row];
+
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellContent.reuseIdentifier];
+
+ if (cell == nil) {
+ cell = [[[[cellContent tableViewCellSubclass] alloc] initWithStyle:cellContent.cellStyle reuseIdentifier:cellContent.reuseIdentifier] autorelease];
+ }
+
+ cell.imageView.image = nil;
+ cell.accessoryView = nil;
+ cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+
+ cellContent.configureBlock(nil, cell, indexPath);
+
+ return cell;
+}
+
+#pragma mark - Table view delegate
+
+- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ if(!tableView.editing && !tableView.allowsMultipleSelection) [tableView deselectRowAtIndexPath:indexPath animated:YES];
+ if(tableView.editing && !tableView.allowsMultipleSelectionDuringEditing) [tableView deselectRowAtIndexPath:indexPath animated:YES];
+
+ JMStaticContentTableViewSection *sectionContent = [self.staticContentSections objectAtIndex:indexPath.section];
+ JMStaticContentTableViewCell *cellContent = [sectionContent.staticContentCells objectAtIndex:indexPath.row];
+
+ if(cellContent.whenSelectedBlock) {
+ cellContent.whenSelectedBlock(indexPath);
+ }
+}
+
+- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
+ [self.view endEditing:YES];
+}
+
+#pragma mark - Static Content
+
+- (void) removeAllSections {
+ if(self.staticContentSections) {
+ self.staticContentSections = nil;
+ self.staticContentSections = [NSArray array];
+ }
+}
+
+- (void) addSection:(JMStaticContentTableViewControllerAddSectionBlock)b {
+ if(!self.staticContentSections) self.staticContentSections = [NSArray array];
+
+ JMStaticContentTableViewSection *section = [[[JMStaticContentTableViewSection alloc] init] autorelease];
+ section.tableView = self.tableView;
+
+ b(section, [self.staticContentSections count] + 1);
+
+ self.staticContentSections = [self.staticContentSections arrayByAddingObject:section];
+}
+
+- (void) insertSection:(JMStaticContentTableViewControllerAddSectionBlock)b atIndex:(NSUInteger)sectionIndex {
+ [self insertSection:b atIndex:sectionIndex animated:YES];
+}
+- (void) insertSection:(JMStaticContentTableViewControllerAddSectionBlock)b atIndex:(NSUInteger)sectionIndex animated:(BOOL)animated {
+ if(!self.staticContentSections) self.staticContentSections = [NSArray array];
+
+ NSMutableArray *mutableSections = [self.staticContentSections mutableCopy];
+
+ JMStaticContentTableViewSection *section = [[[JMStaticContentTableViewSection alloc] init] autorelease];
+
+ b(section, sectionIndex);
+
+ [mutableSections insertObject:section atIndex:sectionIndex];
+
+ self.staticContentSections = [NSArray arrayWithArray:mutableSections];
+
+ [mutableSections release];
+
+ if(animated) {
+ [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
+ } else {
+ [self.tableView reloadData];
+ }
+}
+
+- (void) removeSectionAtIndex:(NSUInteger)sectionIndex {
+ [self removeSectionAtIndex:sectionIndex animated:YES];
+}
+- (void) removeSectionAtIndex:(NSUInteger)sectionIndex animated:(BOOL)animated {
+ NSMutableArray *sections = [self.staticContentSections mutableCopy];
+
+ [sections removeObjectAtIndex:sectionIndex];
+
+ self.staticContentSections = [NSArray arrayWithArray:sections];
+
+ [sections release];
+
+ if(animated) {
+ [self.tableView beginUpdates];
+
+ [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
+
+ [self.tableView endUpdates];
+ } else {
+ [self.tableView reloadData];
+ }
+}
+
+- (JMStaticContentTableViewSection *) sectionAtIndex:(NSUInteger)sectionIndex {
+ return [self.staticContentSections objectAtIndex:sectionIndex];
+}
+
+
+- (void) insertCell:(JMStaticContentTableViewCellBlock)configurationBlock
+ atIndexPath:(NSIndexPath *)indexPath
+ animated:(BOOL)animated {
+
+ [self insertCell:configurationBlock
+ whenSelected:nil
+ atIndexPath:indexPath
+ animated:YES];
+}
+
+- (void) insertCell:(JMStaticContentTableViewCellBlock)configurationBlock
+ whenSelected:(JMStaticContentTableViewCellWhenSelectedBlock)whenSelectedBlock
+ atIndexPath:(NSIndexPath *)indexPath
+ animated:(BOOL)animated {
+
+ JMStaticContentTableViewSection *section = [self sectionAtIndex:indexPath.section];
+
+ [section insertCell:configurationBlock
+ whenSelected:whenSelectedBlock
+ atIndexPath:indexPath
+ animated:animated];
+}
+
+- (void) setFooterText:(NSString *)footerTextValue {
+ if(footerTextValue != _footerText) {
+ [footerTextValue retain];
+ [_footerText release];
+ _footerText = footerTextValue;
+ }
+
+ if(!footerTextValue) {
+ if([self isViewLoaded]) {
+ self.tableView.tableFooterView = nil;
+ }
+
+ return;
+ }
+
+ if([self isViewLoaded]) {
+ UIView *footerLabelContainerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 0.0)];
+ UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 10.0, 280.0, 0.0)];
+
+ footerLabel.backgroundColor = [UIColor clearColor];
+ footerLabel.font = [UIFont systemFontOfSize:15.0];
+ footerLabel.textColor = [UIColor colorWithRed:61.0/255.0 green:77.0/255.0 blue:99.0/255.0 alpha:1.0];
+ footerLabel.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.65];
+ footerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
+ footerLabel.textAlignment = UITextAlignmentCenter;
+ footerLabel.numberOfLines = 0;
+
+ footerLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+
+ footerLabel.text = self.footerText;
+
+ [footerLabel sizeToFit];
+
+ CGRect footerLabelContainerViewRect = footerLabelContainerView.frame;
+ footerLabelContainerViewRect.size.height = footerLabel.frame.size.height + 10.0;
+ footerLabel.frame = footerLabelContainerViewRect;
+
+ [footerLabelContainerView addSubview:footerLabel];
+
+ CGRect footerLabelFrame = footerLabel.frame;
+ footerLabelFrame.size.width = 260.0;
+ footerLabelFrame.origin.x = 30.0;
+ footerLabelFrame.origin.y = 0.0;
+ footerLabel.frame = footerLabelFrame;
+
+ [footerLabel release];
+
+ CGRect containerFrame = footerLabelContainerView.frame;
+ containerFrame.size.height = footerLabel.frame.size.height + 10.0;
+ footerLabelContainerView.frame = containerFrame;
+
+ self.tableView.tableFooterView = footerLabelContainerView;
+
+ [footerLabelContainerView release];
+ }
+}
+
+@end
26 JMStaticContentTableViewController/JMStaticContentTableViewSection.h
@@ -0,0 +1,26 @@
+#import <Foundation/Foundation.h>
+#import "JMStaticContentTableViewBlocks.h"
+
+@class JMStaticContentTableViewCell;
+
+@interface JMStaticContentTableViewSection : NSObject
+
+@property (nonatomic, assign) UITableView *tableView;
+@property (nonatomic, retain) NSArray *staticContentCells;
+@property (nonatomic, retain) NSString *title;
+
+- (void) addCell:(JMStaticContentTableViewCellBlock)configurationBlock;
+
+- (void) addCell:(JMStaticContentTableViewCellBlock)configurationBlock
+ whenSelected:(JMStaticContentTableViewCellWhenSelectedBlock)whenSelectedBlock;
+
+- (void) insertCell:(JMStaticContentTableViewCellBlock)configurationBlock
+ whenSelected:(JMStaticContentTableViewCellWhenSelectedBlock)whenSelectedBlock
+ atIndexPath:(NSIndexPath *)indexPath
+ animated:(BOOL)animated;
+
+- (void) removeAllCells;
+- (void) removeCellAtIndex:(NSUInteger)rowIndex;
+- (void) removeCellAtIndex:(NSUInteger)rowIndex animated:(BOOL)animated;
+
+@end
94 JMStaticContentTableViewController/JMStaticContentTableViewSection.m
@@ -0,0 +1,94 @@
+#import "JMStaticContentTableViewSection.h"
+#import "JMStaticContentTableViewCell.h"
+
+@implementation JMStaticContentTableViewSection
+
+@synthesize tableView = _tableView;
+@synthesize staticContentCells = _staticContentCells;
+@synthesize title = _title;
+
+- (void) dealloc {
+ self.tableView = nil;
+ [_staticContentCells release];
+ [_title release];
+
+ [super dealloc];
+}
+
+- (void) addCell:(JMStaticContentTableViewCellBlock)configurationBlock {
+ [self addCell:configurationBlock whenSelected:nil];
+}
+
+- (void) addCell:(JMStaticContentTableViewCellBlock)configurationBlock whenSelected:(JMStaticContentTableViewCellWhenSelectedBlock)whenSelectedBlock {
+ if(!self.staticContentCells) self.staticContentCells = [NSArray array];
+
+ JMStaticContentTableViewCell *staticContentCell = [[[JMStaticContentTableViewCell alloc] init] autorelease];
+
+ staticContentCell.configureBlock = configurationBlock;
+ staticContentCell.whenSelectedBlock = whenSelectedBlock;
+
+ configurationBlock(staticContentCell, nil, nil);
+
+ self.staticContentCells = [self.staticContentCells arrayByAddingObject:staticContentCell];
+}
+
+- (void) insertCell:(JMStaticContentTableViewCellBlock)configurationBlock
+ whenSelected:(JMStaticContentTableViewCellWhenSelectedBlock)whenSelectedBlock
+ atIndexPath:(NSIndexPath *)indexPath
+ animated:(BOOL)animated {
+
+ if(!self.staticContentCells) self.staticContentCells = [NSArray array];
+
+ NSMutableArray *mutableCells = [self.staticContentCells mutableCopy];
+
+ JMStaticContentTableViewCell *staticContentCell = [[[JMStaticContentTableViewCell alloc] init] autorelease];
+
+ staticContentCell.configureBlock = configurationBlock;
+ staticContentCell.whenSelectedBlock = whenSelectedBlock;
+
+ configurationBlock(staticContentCell, nil, nil);
+
+ [mutableCells insertObject:staticContentCell atIndex:indexPath.row];
+
+ self.staticContentCells = [NSArray arrayWithArray:mutableCells];
+
+ [mutableCells release];
+
+ if(animated) {
+ [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
+ } else {
+ [self.tableView reloadData];
+ }
+}
+
+- (void) removeCellAtIndex:(NSUInteger)rowIndex {
+ [self removeCellAtIndex:rowIndex animated:YES];
+}
+- (void) removeCellAtIndex:(NSUInteger)rowIndex animated:(BOOL)animated {
+ NSMutableArray *cells = [self.staticContentCells mutableCopy];
+
+ [cells removeObjectAtIndex:rowIndex];
+
+ self.staticContentCells = [NSArray arrayWithArray:cells];
+
+ [cells release];
+
+ if(animated) {
+ [self.tableView beginUpdates];
+
+ [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:rowIndex inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
+
+ [self.tableView endUpdates];
+ } else {
+ [self.tableView reloadData];
+ }
+}
+
+- (void) removeAllCells {
+ if(self.staticContentCells) {
+ self.staticContentCells = nil;
+ self.staticContentCells = [NSArray array];
+ }
+}
+
+@end
8 JMStaticContentTableViewController/StaticTextFieldTableViewCell.h
@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+#import "JMStaticContentTableViewCell.h"
+
+@interface StaticTextFieldTableViewCell : JMStaticContentTableViewCell
+
+@property (nonatomic, retain) UITextField *contentTextField;
+
+@end
13 JMStaticContentTableViewController/StaticTextFieldTableViewCell.m
@@ -0,0 +1,13 @@
+#import "StaticTextFieldTableViewCell.h"
+
+@implementation StaticTextFieldTableViewCell
+
+@synthesize contentTextField = _contentTextField;
+
+- (void) dealloc {
+ [_contentTextField release];
+
+ [super dealloc];
+}
+
+@end
0  README.markdown
No changes.
1  SettingsExample
@@ -0,0 +1 @@
+Subproject commit bc7c3fe41115ef3ba3a0acb4ad691d0ea0408cb9
Please sign in to comment.
Something went wrong with that request. Please try again.