From a4c0d3cf67e13b687bf27b57cd8a855bb92b6aa8 Mon Sep 17 00:00:00 2001 From: Roman Efimov Date: Thu, 4 Apr 2013 17:18:56 -0500 Subject: [PATCH] Refactor bunch of code, add cellDidLoad method --- .../Cells/RETableViewBoolCell.m | 16 ++- .../Cells/RETableViewCreditCardCell.m | 114 +++++++++-------- .../Cells/RETableViewNumberCell.h | 30 +---- .../Cells/RETableViewNumberCell.m | 117 ++++-------------- .../Cells/RETableViewTextCell.h | 2 +- .../Cells/RETableViewTextCell.m | 26 ++-- RETableViewManager/Items/RENumberItem.h | 10 +- RETableViewManager/RETableViewCell.h | 2 +- RETableViewManager/RETableViewCell.m | 23 ++-- RETableViewManager/RETableViewManager.m | 4 +- .../project.pbxproj | 12 +- .../Controllers/ControlsViewController.m | 1 + .../Classes/Views/ListImageCell.m | 4 +- 13 files changed, 145 insertions(+), 216 deletions(-) diff --git a/RETableViewManager/Cells/RETableViewBoolCell.m b/RETableViewManager/Cells/RETableViewBoolCell.m index 632b691..a2778ab 100644 --- a/RETableViewManager/Cells/RETableViewBoolCell.m +++ b/RETableViewManager/Cells/RETableViewBoolCell.m @@ -27,18 +27,24 @@ @implementation RETableViewBoolCell -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { - self = [super initWithStyle:style reuseIdentifier:reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager]; + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; - _switchView = [[UISwitch alloc] init]; - [_switchView addTarget:self action:@selector(switchValueDidChanged:) forControlEvents:UIControlEventValueChanged]; - self.accessoryView = _switchView; } return self; } +- (void)cellDidLoad +{ + [super cellDidLoad]; + + _switchView = [[UISwitch alloc] init]; + [_switchView addTarget:self action:@selector(switchValueDidChanged:) forControlEvents:UIControlEventValueChanged]; + self.accessoryView = _switchView; +} + - (void)prepare { self.textLabel.text = self.item.title; diff --git a/RETableViewManager/Cells/RETableViewCreditCardCell.m b/RETableViewManager/Cells/RETableViewCreditCardCell.m index 6d9d5bf..606841f 100644 --- a/RETableViewManager/Cells/RETableViewCreditCardCell.m +++ b/RETableViewManager/Cells/RETableViewCreditCardCell.m @@ -28,7 +28,7 @@ @implementation RETableViewCreditCardCell -static inline NSString *RECreditCardType(NSString *creditCardNumber) +static inline NSString * RECreditCardType(NSString *creditCardNumber) { NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\D" options:NSRegularExpressionCaseInsensitive error:NULL]; NSString *strippedNumber = [regex stringByReplacingMatchesInString:creditCardNumber options:0 range:NSMakeRange(0, creditCardNumber.length) withTemplate:@""]; @@ -46,67 +46,73 @@ static inline NSString *RECreditCardType(NSString *creditCardNumber) return nil; } -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { - self = [super initWithStyle:style reuseIdentifier:reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager]; + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.textLabel.backgroundColor = [UIColor clearColor]; - _creditCardImageViewContainer = [[UIView alloc] initWithFrame:CGRectMake(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 20 : 56, 5, 32, 32)]; - [self addSubview:_creditCardImageViewContainer]; - - _creditCardStackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; - _creditCardStackImageView.image = [UIImage imageNamed:@"RETableViewManager.bundle/Card_Stack"]; - _creditCardStackImageView.tag = 0; - _currentImageView = _creditCardStackImageView; - [_creditCardImageViewContainer addSubview:_creditCardStackImageView]; - - _creditCardImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; - _creditCardImageView.image = [UIImage imageNamed:@"RETableViewManager.bundle/Card_Visa"]; - _creditCardImageView.tag = 1; - - _creditCardBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; - _creditCardBackImageView.image = [UIImage imageNamed:@"RETableViewManager.bundle/Card_Back"]; - _creditCardBackImageView.tag = 2; - - _wrapperView = [[UIView alloc] initWithFrame:CGRectMake(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 60 : 96 + _textFieldPositionOffset.width, _textFieldPositionOffset.height, self.frame.size.width - 70, self.frame.size.height)]; - _wrapperView.clipsToBounds = YES; - [self addSubview:_wrapperView]; - - _creditCardField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(0, 0, 216, self.frame.size.height - _textFieldPositionOffset.height)]; - _creditCardField.tag = 0; - _creditCardField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - _creditCardField.inputAccessoryView = self.actionBar; - _creditCardField.delegate = self; - _creditCardField.placeholder = @"1234 1234 1234 1234"; - _creditCardField.format = @"XXXX XXXX XXXX XXXX"; - [_creditCardField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; - [_wrapperView addSubview:_creditCardField]; - - - _expirationDateField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(320, 0, 80, self.frame.size.height)]; - _expirationDateField.tag = 1; - _expirationDateField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - _expirationDateField.inputAccessoryView = self.actionBar; - _expirationDateField.format = @"XX/XX"; - _expirationDateField.placeholder = @"MM/YY"; - _expirationDateField.delegate = self; - [_expirationDateField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; - [_wrapperView addSubview:_expirationDateField]; - - _cvvField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(320, 0, 60, self.frame.size.height)]; - _cvvField.tag = 2; - _cvvField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - _cvvField.inputAccessoryView = self.actionBar; - _cvvField.format = @"XXX"; - _cvvField.placeholder = @"CVV"; - _cvvField.delegate = self; - [_cvvField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; - [_wrapperView addSubview:_cvvField]; } return self; } +- (void)cellDidLoad +{ + [super cellDidLoad]; + + _creditCardImageViewContainer = [[UIView alloc] initWithFrame:CGRectMake(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 20 : 56, 5, 32, 32)]; + [self addSubview:_creditCardImageViewContainer]; + + _creditCardStackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; + _creditCardStackImageView.image = [UIImage imageNamed:@"RETableViewManager.bundle/Card_Stack"]; + _creditCardStackImageView.tag = 0; + _currentImageView = _creditCardStackImageView; + [_creditCardImageViewContainer addSubview:_creditCardStackImageView]; + + _creditCardImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; + _creditCardImageView.image = [UIImage imageNamed:@"RETableViewManager.bundle/Card_Visa"]; + _creditCardImageView.tag = 1; + + _creditCardBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; + _creditCardBackImageView.image = [UIImage imageNamed:@"RETableViewManager.bundle/Card_Back"]; + _creditCardBackImageView.tag = 2; + + _wrapperView = [[UIView alloc] initWithFrame:CGRectMake(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 60 : 96 + _textFieldPositionOffset.width, _textFieldPositionOffset.height, self.frame.size.width - 70, self.frame.size.height)]; + _wrapperView.clipsToBounds = YES; + [self addSubview:_wrapperView]; + + _creditCardField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(0, 0, 216, self.frame.size.height - _textFieldPositionOffset.height)]; + _creditCardField.tag = 0; + _creditCardField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + _creditCardField.inputAccessoryView = self.actionBar; + _creditCardField.delegate = self; + _creditCardField.placeholder = @"1234 1234 1234 1234"; + _creditCardField.format = @"XXXX XXXX XXXX XXXX"; + [_creditCardField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; + [_wrapperView addSubview:_creditCardField]; + + + _expirationDateField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(320, 0, 80, self.frame.size.height)]; + _expirationDateField.tag = 1; + _expirationDateField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + _expirationDateField.inputAccessoryView = self.actionBar; + _expirationDateField.format = @"XX/XX"; + _expirationDateField.placeholder = @"MM/YY"; + _expirationDateField.delegate = self; + [_expirationDateField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; + [_wrapperView addSubview:_expirationDateField]; + + _cvvField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(320, 0, 60, self.frame.size.height)]; + _cvvField.tag = 2; + _cvvField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + _cvvField.inputAccessoryView = self.actionBar; + _cvvField.format = @"XXX"; + _cvvField.placeholder = @"CVV"; + _cvvField.delegate = self; + [_cvvField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; + [_wrapperView addSubview:_cvvField]; +} + - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; diff --git a/RETableViewManager/Cells/RETableViewNumberCell.h b/RETableViewManager/Cells/RETableViewNumberCell.h index 24451df..6d06be5 100644 --- a/RETableViewManager/Cells/RETableViewNumberCell.h +++ b/RETableViewManager/Cells/RETableViewNumberCell.h @@ -1,36 +1,18 @@ // -// RETableViewNumberCell.h -// RETableViewManager +// RETableViewNumberCell.h +// RETableViewManagerExample // -// 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. +// Created by Roman Efimov on 4/4/13. +// Copyright (c) 2013 Roman Efimov. All rights reserved. // -#import "RETableViewCell.h" +#import "RETableViewTextCell.h" #import "REFormattedNumberField.h" #import "RENumberItem.h" -@interface RETableViewNumberCell : RETableViewCell +@interface RETableViewNumberCell : RETableViewTextCell @property (strong, readwrite, nonatomic) RENumberItem *item; @property (strong, readwrite, nonatomic) REFormattedNumberField *textField; -@property (assign, readwrite, nonatomic) CGSize textFieldPositionOffset; @end diff --git a/RETableViewManager/Cells/RETableViewNumberCell.m b/RETableViewManager/Cells/RETableViewNumberCell.m index 699596e..2ac8035 100644 --- a/RETableViewManager/Cells/RETableViewNumberCell.m +++ b/RETableViewManager/Cells/RETableViewNumberCell.m @@ -1,26 +1,9 @@ // -// RETableViewNumberCell.m -// RETableViewManager +// RETableViewNumberCell.m +// RETableViewManagerExample // -// 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. +// Created by Roman Efimov on 4/4/13. +// Copyright (c) 2013 Roman Efimov. All rights reserved. // #import "RETableViewNumberCell.h" @@ -28,33 +11,27 @@ @implementation RETableViewNumberCell -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { - self = [super initWithStyle:style reuseIdentifier:reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager]; + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.textLabel.backgroundColor = [UIColor clearColor]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) - _textField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(140, 0, self.frame.size.width - 160, self.frame.size.height)]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) - _textField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(160, 0, self.frame.size.width - 200, self.frame.size.height)]; - - _textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - _textField.inputAccessoryView = self.actionBar; - _textField.autoresizingMask = UIViewAutoresizingFlexibleWidth; - _textField.delegate = self; - [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; - [self addSubview:_textField]; } return self; } -- (void)setSelected:(BOOL)selected animated:(BOOL)animated +- (void)cellDidLoad { - [super setSelected:selected animated:animated]; - if (selected) { - [_textField becomeFirstResponder]; - } + [super cellDidLoad]; + self.textField = [[REFormattedNumberField alloc] initWithFrame:CGRectNull]; + + self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + self.textField.inputAccessoryView = self.actionBar; + self.textField.autoresizingMask = UIViewAutoresizingFlexibleWidth; + self.textField.delegate = self; + [self.textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; + [self addSubview:self.textField]; } - (void)prepare @@ -62,61 +39,13 @@ [super prepare]; self.textLabel.text = self.item.title; - _textField.text = self.item.value; - _textField.placeholder = self.item.placeholder; - _textField.format = self.item.format; - _textField.font = self.tableViewManager.style.textFieldFont; - _textFieldPositionOffset = self.tableViewManager.style.textFieldPositionOffset; - _textField.keyboardAppearance = self.item.keyboardAppearance; -} - - -- (UIResponder *)responder -{ - return _textField; -} - -- (void)layoutSubviews -{ - [super layoutSubviews]; - if (self.item.title) { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) - _textField.frame = CGRectMake(140 + _textFieldPositionOffset.width, _textFieldPositionOffset.height, self.frame.size.width - 160, self.frame.size.height - _textFieldPositionOffset.height); - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) - _textField.frame = CGRectMake(160+ _textFieldPositionOffset.width, _textFieldPositionOffset.height, self.frame.size.width - 200, self.frame.size.height - _textFieldPositionOffset.height); - } else { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) - _textField.frame = CGRectMake(20+ _textFieldPositionOffset.width, _textFieldPositionOffset.height, self.frame.size.width - 40, self.frame.size.height - _textFieldPositionOffset.height); - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) - _textField.frame = CGRectMake(40+ _textFieldPositionOffset.width, _textFieldPositionOffset.height, self.frame.size.width - 80, self.frame.size.height - _textFieldPositionOffset.height); - } -} - -#pragma mark - -#pragma mark UISwitch events - -- (void)textFieldDidChange:(UITextField *)textField -{ - self.item.value = textField.text; -} - -- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField -{ - [self refreshActionBar]; - [self.parentTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.row inSection:self.sectionIndex] atScrollPosition:UITableViewScrollPositionTop animated:YES]; - return YES; -} - -- (BOOL)textFieldShouldReturn:(UITextField *)textField -{ - NSIndexPath *indexPath = [self indexPathForNextResponder]; - if (!indexPath) { - [self endEditing:YES]; - return YES; - } - RETableViewCell *cell = (RETableViewCell *)[self.parentTableView cellForRowAtIndexPath:indexPath]; - [cell.responder becomeFirstResponder]; - return YES; + self.textField.text = self.item.value; + self.textField.placeholder = self.item.placeholder; + self.textField.format = self.item.format; + self.textField.font = self.tableViewManager.style.textFieldFont; + self.textFieldPositionOffset = self.tableViewManager.style.textFieldPositionOffset; + self.textField.keyboardAppearance = self.item.keyboardAppearance; + self.textField.keyboardType = UIKeyboardTypeNumberPad; } @end diff --git a/RETableViewManager/Cells/RETableViewTextCell.h b/RETableViewManager/Cells/RETableViewTextCell.h index 98d2e4a..3b6af51 100644 --- a/RETableViewManager/Cells/RETableViewTextCell.h +++ b/RETableViewManager/Cells/RETableViewTextCell.h @@ -29,7 +29,7 @@ @interface RETableViewTextCell : RETableViewCell @property (strong, readwrite, nonatomic) RETextItem *item; -@property (strong, readonly, nonatomic) UITextField *textField; +@property (strong, readwrite, nonatomic) UITextField *textField; @property (assign, readwrite, nonatomic) CGSize textFieldPositionOffset; @end diff --git a/RETableViewManager/Cells/RETableViewTextCell.m b/RETableViewManager/Cells/RETableViewTextCell.m index 7c592d8..2af8ac3 100644 --- a/RETableViewManager/Cells/RETableViewTextCell.m +++ b/RETableViewManager/Cells/RETableViewTextCell.m @@ -28,24 +28,30 @@ @implementation RETableViewTextCell -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { - self = [super initWithStyle:style reuseIdentifier:reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager]; + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.textLabel.backgroundColor = [UIColor clearColor]; - _textField = [[UITextField alloc] initWithFrame:CGRectNull]; - - _textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - _textField.inputAccessoryView = self.actionBar; - _textField.autoresizingMask = UIViewAutoresizingFlexibleWidth; - _textField.delegate = self; - [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; - [self addSubview:_textField]; } return self; } +- (void)cellDidLoad +{ + [super cellDidLoad]; + + _textField = [[UITextField alloc] initWithFrame:CGRectNull]; + + _textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + _textField.inputAccessoryView = self.actionBar; + _textField.autoresizingMask = UIViewAutoresizingFlexibleWidth; + _textField.delegate = self; + [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; + [self addSubview:_textField]; +} + - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; diff --git a/RETableViewManager/Items/RENumberItem.h b/RETableViewManager/Items/RENumberItem.h index c9f5847..201b5d5 100644 --- a/RETableViewManager/Items/RENumberItem.h +++ b/RETableViewManager/Items/RENumberItem.h @@ -25,17 +25,9 @@ #import "RETextItem.h" -@interface RENumberItem : RETableViewItem +@interface RENumberItem : RETextItem -// Data and values -// @property (copy, readwrite, nonatomic) NSString *format; -@property (copy, readwrite, nonatomic) NSString *value; -@property (copy, readwrite, nonatomic) NSString *placeholder; - -// Keyboard -// -@property (assign, readwrite, nonatomic) UIKeyboardAppearance keyboardAppearance; // default is UIKeyboardAppearanceDefault + (id)itemWithTitle:(NSString *)title value:(NSString *)value placeholder:(NSString *)placeholder format:(NSString *)format; - (id)initWithTitle:(NSString *)title value:(NSString *)value placeholder:(NSString *)placeholder format:(NSString *)format; diff --git a/RETableViewManager/RETableViewCell.h b/RETableViewManager/RETableViewCell.h index 7d36cfe..d873f8e 100644 --- a/RETableViewManager/RETableViewCell.h +++ b/RETableViewManager/RETableViewCell.h @@ -43,7 +43,7 @@ + (CGFloat)heightWithItem:(NSObject *)item tableViewManager:(RETableViewManager *)tableViewManager; -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager; +- (void)cellDidLoad; - (void)prepare; - (void)refreshActionBar; diff --git a/RETableViewManager/RETableViewCell.m b/RETableViewManager/RETableViewCell.m index 940f29c..a5a5f17 100644 --- a/RETableViewManager/RETableViewCell.m +++ b/RETableViewManager/RETableViewCell.m @@ -28,22 +28,27 @@ @implementation RETableViewCell -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { - self.tableViewManager = tableViewManager; - self.actionBar = [[REActionBar alloc] initWithDelegate:self]; - if ([self hasCustomBackgroundImage]) { - self.backgroundView = [[UIView alloc] initWithFrame:self.contentView.bounds]; - self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - _backgroundImageView = [[UIImageView alloc] init]; - [self.backgroundView addSubview:_backgroundImageView]; - } + } return self; } +- (void)cellDidLoad +{ + self.actionBar = [[REActionBar alloc] initWithDelegate:self]; + + if ([self hasCustomBackgroundImage]) { + self.backgroundView = [[UIView alloc] initWithFrame:self.contentView.bounds]; + self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + _backgroundImageView = [[UIImageView alloc] init]; + [self.backgroundView addSubview:_backgroundImageView]; + } +} + - (BOOL)hasCustomBackgroundImage { return [self.tableViewManager.style backgroundImageForCellType:RETableViewCellFirst] || [self.tableViewManager.style backgroundImageForCellType:RETableViewCellMiddle] || [self.tableViewManager.style backgroundImageForCellType:RETableViewCellLast] || [self.tableViewManager.style backgroundImageForCellType:RETableViewCellSingle]; diff --git a/RETableViewManager/RETableViewManager.m b/RETableViewManager/RETableViewManager.m index 5e96f3f..9dfc323 100644 --- a/RETableViewManager/RETableViewManager.m +++ b/RETableViewManager/RETableViewManager.m @@ -115,7 +115,9 @@ RETableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { - cell = [[cellClass alloc] initWithStyle:cellStyle reuseIdentifier:cellIdentifier tableViewManager:self]; + cell = [[cellClass alloc] initWithStyle:cellStyle reuseIdentifier:cellIdentifier]; + cell.tableViewManager = self; + [cell cellDidLoad]; } cell.row = indexPath.row; diff --git a/RETableViewManagerExample/RETableViewManagerExample.xcodeproj/project.pbxproj b/RETableViewManagerExample/RETableViewManagerExample.xcodeproj/project.pbxproj index 68878a0..6760f15 100644 --- a/RETableViewManagerExample/RETableViewManagerExample.xcodeproj/project.pbxproj +++ b/RETableViewManagerExample/RETableViewManagerExample.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ 302D2163170B27ED0085654F /* ListImageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 302D2162170B27ED0085654F /* ListImageCell.m */; }; 30DB066A16E934AD006C9530 /* RETableViewBoolCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB064916E934AD006C9530 /* RETableViewBoolCell.m */; }; 30DB066B16E934AD006C9530 /* RETableViewCreditCardCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB064B16E934AD006C9530 /* RETableViewCreditCardCell.m */; }; - 30DB066C16E934AD006C9530 /* RETableViewNumberCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB064D16E934AD006C9530 /* RETableViewNumberCell.m */; }; 30DB066E16E934AD006C9530 /* RETableViewTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB065116E934AD006C9530 /* RETableViewTextCell.m */; }; 30DB066F16E934AD006C9530 /* REBoolItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB065416E934AD006C9530 /* REBoolItem.m */; }; 30DB067016E934AD006C9530 /* RECreditCardItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB065616E934AD006C9530 /* RECreditCardItem.m */; }; @@ -39,6 +38,7 @@ 30EF93C916E039B800B84981 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 30EF93C816E039B800B84981 /* Default-568h@2x.png */; }; 30F41318170E07BB0004EBAE /* RETableViewOptionsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 30F41317170E07BB0004EBAE /* RETableViewOptionsController.m */; }; 30F4131B170E0F620004EBAE /* RERadioItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 30F4131A170E0F620004EBAE /* RERadioItem.m */; }; + 30F4138E170E2E820004EBAE /* RETableViewNumberCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30F4138D170E2E820004EBAE /* RETableViewNumberCell.m */; }; E336F792A48A4E779EEA5AC0 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ABAE09A51FA5498F94EE3798 /* libPods.a */; }; /* End PBXBuildFile section */ @@ -59,8 +59,6 @@ 30DB064916E934AD006C9530 /* RETableViewBoolCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RETableViewBoolCell.m; sourceTree = ""; }; 30DB064A16E934AD006C9530 /* RETableViewCreditCardCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RETableViewCreditCardCell.h; sourceTree = ""; }; 30DB064B16E934AD006C9530 /* RETableViewCreditCardCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RETableViewCreditCardCell.m; sourceTree = ""; }; - 30DB064C16E934AD006C9530 /* RETableViewNumberCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RETableViewNumberCell.h; sourceTree = ""; }; - 30DB064D16E934AD006C9530 /* RETableViewNumberCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RETableViewNumberCell.m; sourceTree = ""; }; 30DB065016E934AD006C9530 /* RETableViewTextCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RETableViewTextCell.h; sourceTree = ""; }; 30DB065116E934AD006C9530 /* RETableViewTextCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RETableViewTextCell.m; sourceTree = ""; }; 30DB065316E934AD006C9530 /* REBoolItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = REBoolItem.h; sourceTree = ""; }; @@ -101,6 +99,8 @@ 30F41317170E07BB0004EBAE /* RETableViewOptionsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RETableViewOptionsController.m; sourceTree = ""; }; 30F41319170E0F620004EBAE /* RERadioItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RERadioItem.h; sourceTree = ""; }; 30F4131A170E0F620004EBAE /* RERadioItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RERadioItem.m; sourceTree = ""; }; + 30F4138C170E2E820004EBAE /* RETableViewNumberCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RETableViewNumberCell.h; sourceTree = ""; }; + 30F4138D170E2E820004EBAE /* RETableViewNumberCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RETableViewNumberCell.m; sourceTree = ""; }; A20B0252928045F5B81B21AF /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; }; ABAE09A51FA5498F94EE3798 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -195,10 +195,10 @@ 30DB064916E934AD006C9530 /* RETableViewBoolCell.m */, 30DB064A16E934AD006C9530 /* RETableViewCreditCardCell.h */, 30DB064B16E934AD006C9530 /* RETableViewCreditCardCell.m */, - 30DB064C16E934AD006C9530 /* RETableViewNumberCell.h */, - 30DB064D16E934AD006C9530 /* RETableViewNumberCell.m */, 30DB065016E934AD006C9530 /* RETableViewTextCell.h */, 30DB065116E934AD006C9530 /* RETableViewTextCell.m */, + 30F4138C170E2E820004EBAE /* RETableViewNumberCell.h */, + 30F4138D170E2E820004EBAE /* RETableViewNumberCell.m */, ); path = Cells; sourceTree = ""; @@ -363,7 +363,6 @@ 30EF93C316E039B800B84981 /* AppDelegate.m in Sources */, 30DB066A16E934AD006C9530 /* RETableViewBoolCell.m in Sources */, 30DB066B16E934AD006C9530 /* RETableViewCreditCardCell.m in Sources */, - 30DB066C16E934AD006C9530 /* RETableViewNumberCell.m in Sources */, 30DB066E16E934AD006C9530 /* RETableViewTextCell.m in Sources */, 30DB066F16E934AD006C9530 /* REBoolItem.m in Sources */, 30DB067016E934AD006C9530 /* RECreditCardItem.m in Sources */, @@ -383,6 +382,7 @@ 302D2163170B27ED0085654F /* ListImageCell.m in Sources */, 30F41318170E07BB0004EBAE /* RETableViewOptionsController.m in Sources */, 30F4131B170E0F620004EBAE /* RERadioItem.m in Sources */, + 30F4138E170E2E820004EBAE /* RETableViewNumberCell.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/RETableViewManagerExample/RETableViewManagerExample/Classes/Controllers/ControlsViewController.m b/RETableViewManagerExample/RETableViewManagerExample/Classes/Controllers/ControlsViewController.m index b424f96..fa5d840 100644 --- a/RETableViewManagerExample/RETableViewManagerExample/Classes/Controllers/ControlsViewController.m +++ b/RETableViewManagerExample/RETableViewManagerExample/Classes/Controllers/ControlsViewController.m @@ -71,6 +71,7 @@ section = [[RETableViewSection alloc] initWithHeaderTitle:@"Basic controls"]; [_manager addSection:section]; [section addItem:[RETextItem itemWithTitle:@"Text item 1" value:nil placeholder:@"Text"]]; + [section addItem:[RENumberItem itemWithTitle:@"Phone" value:@"" placeholder:@"(123) 456-7890" format:@"(XXX) XXX-XXXX"]]; section = [[RETableViewSection alloc] initWithHeaderTitle:@"Credit card"]; [_manager addSection:section]; diff --git a/RETableViewManagerExample/RETableViewManagerExample/Classes/Views/ListImageCell.m b/RETableViewManagerExample/RETableViewManagerExample/Classes/Views/ListImageCell.m index 7897264..3666c23 100644 --- a/RETableViewManagerExample/RETableViewManagerExample/Classes/Views/ListImageCell.m +++ b/RETableViewManagerExample/RETableViewManagerExample/Classes/Views/ListImageCell.m @@ -16,9 +16,9 @@ return 306; } -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { - self = [super initWithStyle:style reuseIdentifier:reuseIdentifier tableViewManager:tableViewManager]; + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { _pictureView = [[UIImageView alloc] initWithFrame:CGRectMake(7, 0, 306, 306)]; [self addSubview:_pictureView];