commit 7e06188b3736569a3f4c35b1c30362a73f7c1d2b Author: Roman Efimov Date: Thu Feb 28 17:45:34 2013 -0600 Initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a15fab6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego). + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/RETableViewManager/REBoolItem.h b/RETableViewManager/REBoolItem.h new file mode 100644 index 0000000..85537e0 --- /dev/null +++ b/RETableViewManager/REBoolItem.h @@ -0,0 +1,38 @@ +// +// REBoolItem.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewItem.h" + +@interface REBoolItem : RETableViewItem + +@property (assign, nonatomic) BOOL value; + ++ (id)itemWithTitle:(NSString *)title value:(BOOL)value actionBlock:(void(^)(REBoolItem *item))actionBlock; ++ (id)itemWithTitle:(NSString *)title value:(BOOL)value; + +- (id)initWithTitle:(NSString *)title value:(BOOL)value actionBlock:(void(^)(REBoolItem *item))actionBlock; +- (id)initWithTitle:(NSString *)title value:(BOOL)value; + +@end diff --git a/RETableViewManager/REBoolItem.m b/RETableViewManager/REBoolItem.m new file mode 100644 index 0000000..e868a55 --- /dev/null +++ b/RETableViewManager/REBoolItem.m @@ -0,0 +1,58 @@ +// +// REBoolItem.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "REBoolItem.h" + +@implementation REBoolItem + ++ (id)itemWithTitle:(NSString *)title value:(BOOL)value +{ + return [[REBoolItem alloc] initWithTitle:title value:value]; +} + ++ (id)itemWithTitle:(NSString *)title value:(BOOL)value actionBlock:(void(^)(REBoolItem *item))actionBlock +{ + return [[REBoolItem alloc] initWithTitle:title value:value actionBlock:actionBlock]; +} + +- (id)initWithTitle:(NSString *)title value:(BOOL)value +{ + return [self initWithTitle:title value:value actionBlock:nil]; +} + +- (id)initWithTitle:(NSString *)title value:(BOOL)value actionBlock:(void(^)(REBoolItem *item))actionBlock +{ + self = [super init]; + if (!self) + return nil; + + self.title = title; + self.value = value; + self.actionBlock = actionBlock; + + return self; +} + +@end diff --git a/RETableViewManager/REStringItem.h b/RETableViewManager/REStringItem.h new file mode 100644 index 0000000..d6b9348 --- /dev/null +++ b/RETableViewManager/REStringItem.h @@ -0,0 +1,38 @@ +// +// REStringItem.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewItem.h" + +@interface REStringItem : RETableViewItem + +@property (assign, nonatomic) UITableViewCellAccessoryType accessoryType; +@property (strong, nonatomic) UIView *accessoryView; + ++ (id)itemWithTitle:(NSString *)title actionBlock:(void(^)(RETableViewItem *item))actionBlock accessoryType:(UITableViewCellAccessoryType)accessoryType; ++ (id)itemWithTitle:(NSString *)title actionBlock:(void(^)(RETableViewItem *item))actionBlock accessoryType:(UITableViewCellAccessoryType)accessoryType accessoryView:(UIView *)accessoryView; +- (id)initWithTitle:(NSString *)title actionBlock:(void(^)(RETableViewItem *item))actionBlock accessoryType:(UITableViewCellAccessoryType)accessoryType; +- (id)initWithTitle:(NSString *)title actionBlock:(void(^)(RETableViewItem *item))actionBlock accessoryType:(UITableViewCellAccessoryType)accessoryType accessoryView:(UIView *)accessoryView; + +@end diff --git a/RETableViewManager/REStringItem.m b/RETableViewManager/REStringItem.m new file mode 100644 index 0000000..1a000d4 --- /dev/null +++ b/RETableViewManager/REStringItem.m @@ -0,0 +1,60 @@ +// +// REStringItem.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "REStringItem.h" + +@implementation REStringItem + ++ (id)itemWithTitle:(NSString *)title actionBlock:(void(^)(RETableViewItem *item))actionBlock accessoryType:(UITableViewCellAccessoryType)accessoryType +{ + return [[REStringItem alloc] initWithTitle:title actionBlock:actionBlock accessoryType:accessoryType accessoryView:nil]; +} + ++ (id)itemWithTitle:(NSString *)title actionBlock:(void(^)(RETableViewItem *item))actionBlock accessoryType:(UITableViewCellAccessoryType)accessoryType accessoryView:(UIView *)accessoryView +{ + return [[REStringItem alloc] initWithTitle:title actionBlock:actionBlock accessoryType:accessoryType accessoryView:accessoryView]; +} + +- (id)initWithTitle:(NSString *)title actionBlock:(void(^)(RETableViewItem *item))actionBlock accessoryType:(UITableViewCellAccessoryType)accessoryType; +{ + return [self initWithTitle:title actionBlock:actionBlock accessoryType:accessoryType accessoryView:nil]; +} + +- (id)initWithTitle:(NSString *)title actionBlock:(void(^)(RETableViewItem *item))actionBlock accessoryType:(UITableViewCellAccessoryType)accessoryType accessoryView:(UIView *)accessoryView +{ + self = [super init]; + if (!self) + return nil; + + self.title = title; + self.accessoryType = accessoryType; + self.accessoryView = accessoryView; + self.actionBlock = actionBlock; + self.performActionOnSelection = YES; + + return self; +} + +@end diff --git a/RETableViewManager/RETableViewBoolCell.h b/RETableViewManager/RETableViewBoolCell.h new file mode 100644 index 0000000..7094e33 --- /dev/null +++ b/RETableViewManager/RETableViewBoolCell.h @@ -0,0 +1,35 @@ +// +// RETableViewBoolCell.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewCell.h" +#import "REBoolItem.h" + +@interface RETableViewBoolCell : RETableViewCell { + UISwitch *_switch; +} + +@property (strong, nonatomic) REBoolItem *item; + +@end diff --git a/RETableViewManager/RETableViewBoolCell.m b/RETableViewManager/RETableViewBoolCell.m new file mode 100644 index 0000000..4000cfc --- /dev/null +++ b/RETableViewManager/RETableViewBoolCell.m @@ -0,0 +1,58 @@ +// +// RETableViewBoolCell.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewBoolCell.h" + +@implementation RETableViewBoolCell + +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + if (self) { + self.selectionStyle = UITableViewCellSelectionStyleNone; + _switch = [[UISwitch alloc] init]; + [_switch addTarget:self action:@selector(switchValueDidChanged:) forControlEvents:UIControlEventValueChanged]; + self.accessoryView = _switch; + } + return self; +} + +- (void)prepare +{ + self.textLabel.text = self.item.title; + _switch.on = self.item.value; +} + +#pragma mark - +#pragma mark UISwitch events + +- (void)switchValueDidChanged:(UISwitch *)switchView +{ + self.item.value = switchView.isOn; + if (self.item.actionBlock) + self.item.actionBlock(self.item); +} + +@end diff --git a/RETableViewManager/RETableViewCell.h b/RETableViewManager/RETableViewCell.h new file mode 100644 index 0000000..5bdb052 --- /dev/null +++ b/RETableViewManager/RETableViewCell.h @@ -0,0 +1,40 @@ +// +// RETableViewCell.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import +#import "RETableViewSection.h" + +@interface RETableViewCell : UITableViewCell + +@property (assign, nonatomic) NSInteger row; +@property (assign, nonatomic) NSInteger sectionIndex; +@property (weak, nonatomic) UITableView *parentTableView; +@property (weak, nonatomic) RETableViewSection *section; +@property (strong, nonatomic) NSObject *item; + +- (void)prepare; ++ (CGFloat)height; + +@end diff --git a/RETableViewManager/RETableViewCell.m b/RETableViewManager/RETableViewCell.m new file mode 100644 index 0000000..ad34073 --- /dev/null +++ b/RETableViewManager/RETableViewCell.m @@ -0,0 +1,40 @@ +// +// RETableViewCell.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewCell.h" + +@implementation RETableViewCell + ++ (CGFloat)height +{ + return 44; +} + +- (void)prepare +{ + +} + +@end diff --git a/RETableViewManager/RETableViewItem.h b/RETableViewManager/RETableViewItem.h new file mode 100644 index 0000000..ea208c2 --- /dev/null +++ b/RETableViewManager/RETableViewItem.h @@ -0,0 +1,34 @@ +// +// RETableViewItem.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import + +@interface RETableViewItem : NSObject + +@property (copy, nonatomic) NSString *title; +@property (copy, nonatomic) void (^actionBlock)(id item); +@property (assign, nonatomic) BOOL performActionOnSelection; + +@end diff --git a/RETableViewManager/RETableViewItem.m b/RETableViewManager/RETableViewItem.m new file mode 100644 index 0000000..2bbb0db --- /dev/null +++ b/RETableViewManager/RETableViewItem.m @@ -0,0 +1,30 @@ +// +// RETableViewItem.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewItem.h" + +@implementation RETableViewItem + +@end diff --git a/RETableViewManager/RETableViewManager.h b/RETableViewManager/RETableViewManager.h new file mode 100644 index 0000000..c3f3250 --- /dev/null +++ b/RETableViewManager/RETableViewManager.h @@ -0,0 +1,55 @@ +// +// RETableViewManager.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import +#import "RETableViewSection.h" +#import "RETableViewCell.h" +#import "RETableViewStringCell.h" + +#import "REBoolItem.h" +#import "RETextItem.h" + +@protocol RETableViewManagerDelegate; + +@interface RETableViewManager : NSObject + +@property (strong, nonatomic) NSMutableArray *sections; +@property (strong, nonatomic) NSMutableDictionary *mapping; +@property (assign, nonatomic) iddelegate; + +- (void)addSection:(RETableViewSection *)section; +- (void)mapObjectClass:(NSString *)objectClass toTableViewCellClass:(NSString *)cellViewClass; + +@end + +@protocol RETableViewManagerDelegate + +@optional + +- (void)tableView:(UITableView *)tableView styleCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath; +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath item:(id)item; + +@end \ No newline at end of file diff --git a/RETableViewManager/RETableViewManager.m b/RETableViewManager/RETableViewManager.m new file mode 100644 index 0000000..19a87bf --- /dev/null +++ b/RETableViewManager/RETableViewManager.m @@ -0,0 +1,180 @@ +// +// RETableViewManager.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewManager.h" + +@implementation RETableViewManager + +- (id)init +{ + self = [super init]; + if (!self) + return nil; + + _sections = [[NSMutableArray alloc] init]; + _mapping = [[NSMutableDictionary alloc] init]; + + [self setDefaultMapping]; + + return self; +} + +- (void)setDefaultMapping +{ + [self mapObjectClass:@"NSString" toTableViewCellClass:@"RETableViewStringCell"]; + [self mapObjectClass:@"REStringItem" toTableViewCellClass:@"RETableViewStringCell"]; + [self mapObjectClass:@"REBoolItem" toTableViewCellClass:@"RETableViewBoolCell"]; + [self mapObjectClass:@"RETextItem" toTableViewCellClass:@"RETableViewTextCell"]; +} + +- (void)addSection:(RETableViewSection *)section +{ + [_sections addObject:section]; +} + +- (void)mapObjectClass:(NSString *)objectClass toTableViewCellClass:(NSString *)cellViewClass +{ + [_mapping setObject:cellViewClass forKey:objectClass]; +} + +- (Class)classForCellAtIndexPath:(NSIndexPath *)indexPath +{ + RETableViewSection *section = [_sections objectAtIndex:indexPath.section]; + NSObject *item = [section.items objectAtIndex:indexPath.row]; + Class cellClass; + for (NSString *className in _mapping) { + Class objectClass = NSClassFromString(className); + if ([item isKindOfClass:objectClass]) { + cellClass = NSClassFromString([_mapping objectForKey:className]); + break; + } + } + return cellClass; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return _sections.count; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex +{ + RETableViewSection *section = [_sections objectAtIndex:sectionIndex]; + return section.items.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + RETableViewSection *section = [_sections objectAtIndex:indexPath.section]; + NSObject *item = [section.items objectAtIndex:indexPath.row]; + NSString *cellIdentifier = [NSString stringWithFormat:@"RETableViewManager_%@", [item class]]; + + Class cellClass = [self classForCellAtIndexPath:indexPath]; + + RETableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; + if (cell == nil) { + cell = [[cellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; + } + + cell.row = indexPath.row; + cell.sectionIndex = indexPath.section; + cell.parentTableView = tableView; + cell.section = section; + cell.item = item; + [cell prepare]; + + if ([_delegate respondsToSelector:@selector(tableView:styleCell:atIndexPath:)]) + [_delegate tableView:tableView styleCell:cell atIndexPath:indexPath]; + + return cell; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return [[self classForCellAtIndexPath:indexPath] height]; +} + +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)sectionIndex +{ + RETableViewSection *section = [_sections objectAtIndex:sectionIndex]; + return section.headerTitle; +} + +- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)sectionIndex +{ + RETableViewSection *section = [_sections objectAtIndex:sectionIndex]; + return section.footerTitle; +} + +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sectionIndex +{ + RETableViewSection *section = [_sections objectAtIndex:sectionIndex]; + return section.headerView; +} + +- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)sectionIndex +{ + RETableViewSection *section = [_sections objectAtIndex:sectionIndex]; + return section.footerView; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)sectionIndex +{ + RETableViewSection *section = [_sections objectAtIndex:sectionIndex]; + if (section.headerView) + return section.headerView.frame.size.height; + return UITableViewAutomaticDimension; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)sectionIndex +{ + RETableViewSection *section = [_sections objectAtIndex:sectionIndex]; + if (section.footerView) + return section.footerView.frame.size.height; + return UITableViewAutomaticDimension; +} + +#pragma mark - Table view delegate + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + RETableViewSection *section = [_sections objectAtIndex:indexPath.section]; + id item = [section.items objectAtIndex:indexPath.row]; + if ([item respondsToSelector:@selector(setActionBlock:)]) { + RETableViewItem *actionItem = (RETableViewItem *)item; + if (actionItem.actionBlock && actionItem.performActionOnSelection) + actionItem.actionBlock(item); + } + + if ([_delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) + [_delegate tableView:tableView didSelectRowAtIndexPath:indexPath]; + + if ([_delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:item:)]) + [_delegate tableView:tableView didSelectRowAtIndexPath:indexPath item:item]; +} + +@end diff --git a/RETableViewManager/RETableViewSection.h b/RETableViewManager/RETableViewSection.h new file mode 100644 index 0000000..58aabc4 --- /dev/null +++ b/RETableViewManager/RETableViewSection.h @@ -0,0 +1,40 @@ +// +// RETableViewSection.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import + +@interface RETableViewSection : NSObject + +@property (copy, nonatomic) NSString *headerTitle; +@property (copy, nonatomic) NSString *footerTitle; +@property (strong, nonatomic) NSMutableArray *items; + +@property (strong, nonatomic) UIView *headerView; +@property (strong, nonatomic) UIView *footerView; + +- (id)initWithHeaderTitle:(NSString *)headerTitle; +- (void)addItem:(id)item; + +@end diff --git a/RETableViewManager/RETableViewSection.m b/RETableViewManager/RETableViewSection.m new file mode 100644 index 0000000..3a96e44 --- /dev/null +++ b/RETableViewManager/RETableViewSection.m @@ -0,0 +1,56 @@ +// +// RETableViewSection.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewSection.h" + +@implementation RETableViewSection + +- (id)init +{ + self = [super init]; + if (!self) + return nil; + + _items = [[NSMutableArray alloc] init]; + + return self; +} + +- (id)initWithHeaderTitle:(NSString *)headerTitle +{ + self = [self init]; + if (!self) + return nil; + + self.headerTitle = headerTitle; + return self; +} + +- (void)addItem:(id)item +{ + [_items addObject:item]; +} + +@end diff --git a/RETableViewManager/RETableViewStringCell.h b/RETableViewManager/RETableViewStringCell.h new file mode 100644 index 0000000..fc8c07f --- /dev/null +++ b/RETableViewManager/RETableViewStringCell.h @@ -0,0 +1,33 @@ +// +// RETableViewStringCell.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewCell.h" +#import "REStringItem.h" + +@interface RETableViewStringCell : RETableViewCell + +@property (strong, nonatomic) NSString *item; + +@end diff --git a/RETableViewManager/RETableViewStringCell.m b/RETableViewManager/RETableViewStringCell.m new file mode 100644 index 0000000..e86144b --- /dev/null +++ b/RETableViewManager/RETableViewStringCell.m @@ -0,0 +1,51 @@ +// +// RETableViewStringCell.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewStringCell.h" + +@implementation RETableViewStringCell + +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + if (self) { + // Initialization code + } + return self; +} + +- (void)prepare +{ + if ([self.item isKindOfClass:[NSString class]]) { + self.textLabel.text = self.item; + } else { + REStringItem *item = (REStringItem *)self.item; + self.textLabel.text = item.title; + self.accessoryType = item.accessoryType; + self.accessoryView = item.accessoryView; + } +} + +@end diff --git a/RETableViewManager/RETableViewTextCell.h b/RETableViewManager/RETableViewTextCell.h new file mode 100644 index 0000000..8b3842f --- /dev/null +++ b/RETableViewManager/RETableViewTextCell.h @@ -0,0 +1,36 @@ +// +// RETableViewTextCell.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewCell.h" +#import "RETextItem.h" + +@interface RETableViewTextCell : RETableViewCell { + UITextField *_textField; + UISegmentedControl *_prevNext; +} + +@property (strong, nonatomic) RETextItem *item; + +@end diff --git a/RETableViewManager/RETableViewTextCell.m b/RETableViewManager/RETableViewTextCell.m new file mode 100644 index 0000000..6931141 --- /dev/null +++ b/RETableViewManager/RETableViewTextCell.m @@ -0,0 +1,198 @@ +// +// RETableViewTextCell.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewTextCell.h" + +@implementation RETableViewTextCell + +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + if (self) { + self.selectionStyle = UITableViewCellSelectionStyleNone; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) + _textField = [[UITextField alloc] initWithFrame:CGRectMake(140, 0, self.frame.size.width - 160, self.frame.size.height)]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + _textField = [[UITextField alloc] initWithFrame:CGRectMake(160, 0, self.frame.size.width - 200, self.frame.size.height)]; + + _textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + _textField.delegate = self; + [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; + _textField.inputAccessoryView = [self createActionBar]; + + _textField.autoresizingMask = UIViewAutoresizingFlexibleWidth; + [self addSubview:_textField]; + } + return self; +} + +- (UIToolbar *)createActionBar +{ + UIToolbar *actionBar = [[UIToolbar alloc] init]; + actionBar.translucent = YES; + [actionBar sizeToFit]; + actionBar.barStyle = UIBarStyleBlackTranslucent; + + UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"") + style:UIBarButtonItemStyleDone target:self + action:@selector(handleActionBarDone:)]; + + _prevNext = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString(@"Previous", @""), NSLocalizedString(@"Next", @""), nil]]; + _prevNext.momentary = YES; + _prevNext.segmentedControlStyle = UISegmentedControlStyleBar; + _prevNext.tintColor = actionBar.tintColor; + [_prevNext addTarget:self action:@selector(handleActionBarPreviousNext:) forControlEvents:UIControlEventValueChanged]; + UIBarButtonItem *prevNextWrapper = [[UIBarButtonItem alloc] initWithCustomView:_prevNext]; + UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; + [actionBar setItems:[NSArray arrayWithObjects:prevNextWrapper, flexible, doneButton, nil]]; + + return actionBar; +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated +{ + [super setSelected:selected animated:animated]; + if (selected) { + [_textField becomeFirstResponder]; + } +} + +- (void)prepare +{ + self.textLabel.text = self.item.title; + _textField.text = self.item.value; + _textField.placeholder = self.item.placeholder; + + [_prevNext setEnabled:[self indexPathForPreviousTextField] != nil forSegmentAtIndex:0]; + [_prevNext setEnabled:[self indexPathForNextTextField] != nil forSegmentAtIndex:1]; +} + +- (NSIndexPath *)indexPathForPreviousTextField +{ + NSUInteger indexInSection = [self.section.items indexOfObject:self.item]; + for (NSInteger i = indexInSection - 1; i >= 0; i--) { + id item = [self.section.items objectAtIndex:i]; + if ([item isKindOfClass:[RETextItem class]]) { + return [NSIndexPath indexPathForRow:i inSection:self.sectionIndex]; + break; + } + } + return nil; +} + +- (NSIndexPath *)indexPathForNextTextField +{ + NSUInteger indexInSection = [self.section.items indexOfObject:self.item]; + for (NSInteger i = indexInSection + 1; i < self.section.items.count; i++) { + id item = [self.section.items objectAtIndex:i]; + if ([item isKindOfClass:[RETextItem class]]) { + return [NSIndexPath indexPathForRow:i inSection:self.sectionIndex]; + break; + } + } + return nil; +} + +#pragma mark - +#pragma mark UISwitch events + +- (void)textFieldDidChange:(UITextField *)textField +{ + self.item.value = textField.text; +} + +- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField +{ + NSIndexPath *indexPath = [self indexPathForNextTextField]; + if (indexPath) { + textField.returnKeyType = UIReturnKeyNext; + } else { + textField.returnKeyType = UIReturnKeyDefault; + } + + [self.parentTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.row inSection:self.sectionIndex] atScrollPosition:UITableViewScrollPositionTop animated:YES]; + return YES; +} + + +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + NSIndexPath *indexPath = [self indexPathForNextTextField]; + if (!indexPath) { + [_textField resignFirstResponder]; + return YES; + } + UITableViewCell *cell = [self.parentTableView cellForRowAtIndexPath:indexPath]; + for (id object in cell.subviews) { + if ([object isKindOfClass:[UITextField class]]) { + UITextField *textField = object; + [textField becomeFirstResponder]; + } + } + return YES; +} + +#pragma mark - +#pragma mark Action bar + +- (void)handleActionBarPreviousNext:(UISegmentedControl *)segmentedControl +{ + if (segmentedControl.selectedSegmentIndex == 0) { + NSIndexPath *indexPath = [self indexPathForPreviousTextField]; + if (indexPath) { + UITableViewCell *cell = [self.parentTableView cellForRowAtIndexPath:indexPath]; + if (!cell) + [self.parentTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; + cell = [self.parentTableView cellForRowAtIndexPath:indexPath]; + for (id object in cell.subviews) { + if ([object isKindOfClass:[UITextField class]]) { + UITextField *textField = object; + [textField becomeFirstResponder]; + } + } + } + } else { + NSIndexPath *indexPath = [self indexPathForNextTextField]; + if (indexPath) { + UITableViewCell *cell = [self.parentTableView cellForRowAtIndexPath:indexPath]; + if (!cell) + [self.parentTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; + cell = [self.parentTableView cellForRowAtIndexPath:indexPath]; + for (id object in cell.subviews) { + if ([object isKindOfClass:[UITextField class]]) { + UITextField *textField = object; + [textField becomeFirstResponder]; + } + } + } + } +} + +- (void)handleActionBarDone:(UIBarButtonItem *)doneButtonItem +{ + [_textField resignFirstResponder]; +} + +@end diff --git a/RETableViewManager/RETextItem.h b/RETableViewManager/RETextItem.h new file mode 100644 index 0000000..8fe341a --- /dev/null +++ b/RETableViewManager/RETextItem.h @@ -0,0 +1,36 @@ +// +// RETextItem.h +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETableViewItem.h" + +@interface RETextItem : RETableViewItem + +@property (copy, nonatomic) NSString *value; +@property (copy, nonatomic) NSString *placeholder; + ++ (id)itemWithTitle:(NSString *)title value:(NSString *)value; +- (id)initWithTitle:(NSString *)title value:(NSString *)value; + +@end diff --git a/RETableViewManager/RETextItem.m b/RETableViewManager/RETextItem.m new file mode 100644 index 0000000..b87eece --- /dev/null +++ b/RETableViewManager/RETextItem.m @@ -0,0 +1,47 @@ +// +// RETextItem.m +// RETableViewManager +// +// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "RETextItem.h" + +@implementation RETextItem + ++ (id)itemWithTitle:(NSString *)title value:(NSString *)value +{ + return [[RETextItem alloc] initWithTitle:title value:value]; +} + +- (id)initWithTitle:(NSString *)title value:(NSString *)value +{ + self = [super init]; + if (!self) + return nil; + + self.title = title; + self.value = value; + + return self; +} + +@end