diff --git a/RETableViewManager/Cells/RETableViewOptionCell.h b/RETableViewManager/Cells/RETableViewOptionCell.h new file mode 100644 index 0000000..5bb4541 --- /dev/null +++ b/RETableViewManager/Cells/RETableViewOptionCell.h @@ -0,0 +1,34 @@ +// +// RETableViewOptionCell.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 "RERadioItem.h" + +@interface RETableViewOptionCell : RETableViewCell + +@property (strong, readwrite, nonatomic) RERadioItem *item; +@property (strong, readwrite, nonatomic) UILabel *valueLabel; + +@end diff --git a/RETableViewManager/Cells/RETableViewOptionCell.m b/RETableViewManager/Cells/RETableViewOptionCell.m new file mode 100644 index 0000000..8755f1b --- /dev/null +++ b/RETableViewManager/Cells/RETableViewOptionCell.m @@ -0,0 +1,88 @@ +// +// RETableViewOptionCell.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 "RETableViewOptionCell.h" +#import "RETableViewManager.h" + +@implementation RETableViewOptionCell + +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + if (self) { + + } + return self; +} + +- (void)cellDidLoad +{ + [super cellDidLoad]; + self.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + self.selectionStyle = self.tableViewManager.style.defaultCellSelectionStyle; + + _valueLabel = [[UILabel alloc] initWithFrame:CGRectNull]; + _valueLabel.font = [UIFont systemFontOfSize:17]; + _valueLabel.backgroundColor = [UIColor clearColor]; + _valueLabel.textColor = self.detailTextLabel.textColor; + _valueLabel.highlightedTextColor = [UIColor whiteColor]; + _valueLabel.textAlignment = NSTextAlignmentRight; + [self addSubview:_valueLabel]; +} + +- (void)cellWillAppear +{ + self.textLabel.text = self.item.title; + self.detailTextLabel.text = @""; + self.valueLabel.text = self.item.detailLabelText; +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + CGFloat cellOffset = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 20 : 60; + CGFloat fieldOffset = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 10 : 40; + CGFloat width = 0; + CGRect frame = CGRectMake(0, self.tableViewManager.style.textFieldPositionOffset.height - 1, 0, self.frame.size.height - self.tableViewManager.style.textFieldPositionOffset.height); + if (self.item.title && ![self.item.title isEqualToString:@""]) { + for (RETableViewItem *item in self.section.items) { + if ([item isMemberOfClass:[RETextItem class]] || [item isMemberOfClass:[REDateTimeItem class]]) { + CGSize size = [item.title sizeWithFont:self.textLabel.font]; + width = MAX(width, size.width); + } + } + frame.origin.x = width + cellOffset + fieldOffset + self.tableViewManager.style.textFieldPositionOffset.width; + } else { + frame.origin.x = cellOffset + self.tableViewManager.style.textFieldPositionOffset.width; + } + frame.size.width = self.frame.size.width - frame.origin.x - cellOffset - (self.frame.size.width - self.contentView.frame.size.width - cellOffset); + _valueLabel.frame = frame; + + if ([self.tableViewManager.delegate respondsToSelector:@selector(tableView:cellWillLayoutSubviews:)]) + [self.tableViewManager.delegate tableView:self.tableViewManager.tableView cellWillLayoutSubviews:self]; +} + +@end diff --git a/RETableViewManager/RETableViewManager.m b/RETableViewManager/RETableViewManager.m index 6e1e0e6..e706fa3 100644 --- a/RETableViewManager/RETableViewManager.m +++ b/RETableViewManager/RETableViewManager.m @@ -68,7 +68,7 @@ [self registerClass:@"__NSCFString" forCellWithReuseIdentifier:@"RETableViewCell"]; [self registerClass:@"NSString" forCellWithReuseIdentifier:@"RETableViewCell"]; [self registerClass:@"RETableViewItem" forCellWithReuseIdentifier:@"RETableViewCell"]; - [self registerClass:@"RERadioItem" forCellWithReuseIdentifier:@"RETableViewCell"]; + [self registerClass:@"RERadioItem" forCellWithReuseIdentifier:@"RETableViewOptionCell"]; [self registerClass:@"REBoolItem" forCellWithReuseIdentifier:@"RETableViewBoolCell"]; [self registerClass:@"RETextItem" forCellWithReuseIdentifier:@"RETableViewTextCell"]; [self registerClass:@"RELongTextItem" forCellWithReuseIdentifier:@"RETableViewLongTextCell"]; @@ -76,7 +76,7 @@ [self registerClass:@"REFloatItem" forCellWithReuseIdentifier:@"RETableViewFloatCell"]; [self registerClass:@"REDateTimeItem" forCellWithReuseIdentifier:@"RETableViewDateTimeCell"]; [self registerClass:@"RECreditCardItem" forCellWithReuseIdentifier:@"RETableViewCreditCardCell"]; - [self registerClass:@"REMultipleChoiceItem" forCellWithReuseIdentifier:@"RETableViewCell"]; + [self registerClass:@"REMultipleChoiceItem" forCellWithReuseIdentifier:@"RETableViewOptionCell"]; } - (void)registerClass:(NSString *)objectClass forCellWithReuseIdentifier:(NSString *)identifier diff --git a/RETableViewManagerExample/RETableViewManagerExample.xcodeproj/project.pbxproj b/RETableViewManagerExample/RETableViewManagerExample.xcodeproj/project.pbxproj index 2f2d828..e0e7a12 100644 --- a/RETableViewManagerExample/RETableViewManagerExample.xcodeproj/project.pbxproj +++ b/RETableViewManagerExample/RETableViewManagerExample.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 302D2160170B27BD0085654F /* ListImageItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 302D215F170B27BD0085654F /* ListImageItem.m */; }; 302D2163170B27ED0085654F /* ListImageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 302D2162170B27ED0085654F /* ListImageCell.m */; }; 30D208641718FFDE00144E46 /* REMultipleChoiceItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 30D208631718FFDE00144E46 /* REMultipleChoiceItem.m */; }; + 30D74554174EB4CA00D4C7C1 /* RETableViewOptionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30D74553174EB4C900D4C7C1 /* RETableViewOptionCell.m */; }; 30DB066A16E934AD006C9530 /* RETableViewBoolCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB064916E934AD006C9530 /* RETableViewBoolCell.m */; }; 30DB066B16E934AD006C9530 /* RETableViewCreditCardCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB064B16E934AD006C9530 /* RETableViewCreditCardCell.m */; }; 30DB066E16E934AD006C9530 /* RETableViewTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB065116E934AD006C9530 /* RETableViewTextCell.m */; }; @@ -80,6 +81,8 @@ 302D2162170B27ED0085654F /* ListImageCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListImageCell.m; sourceTree = ""; }; 30D208621718FFDE00144E46 /* REMultipleChoiceItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = REMultipleChoiceItem.h; sourceTree = ""; }; 30D208631718FFDE00144E46 /* REMultipleChoiceItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = REMultipleChoiceItem.m; sourceTree = ""; }; + 30D74552174EB4C900D4C7C1 /* RETableViewOptionCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RETableViewOptionCell.h; sourceTree = ""; }; + 30D74553174EB4C900D4C7C1 /* RETableViewOptionCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RETableViewOptionCell.m; sourceTree = ""; }; 30DB064816E934AD006C9530 /* RETableViewBoolCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RETableViewBoolCell.h; sourceTree = ""; }; 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 = ""; }; @@ -236,6 +239,8 @@ 300E5A2E170F63B600910013 /* RETableViewDateTimeCell.m */, 300E5B4017170B0100910013 /* RETableViewLongTextCell.h */, 300E5B4117170B0100910013 /* RETableViewLongTextCell.m */, + 30D74552174EB4C900D4C7C1 /* RETableViewOptionCell.h */, + 30D74553174EB4C900D4C7C1 /* RETableViewOptionCell.m */, ); path = Cells; sourceTree = ""; @@ -437,6 +442,7 @@ 30082D1A17170EDD008B0DB5 /* REPlaceholderTextView.m in Sources */, 30D208641718FFDE00144E46 /* REMultipleChoiceItem.m in Sources */, 30E16A48171A103400F7C258 /* EditingViewController.m in Sources */, + 30D74554174EB4CA00D4C7C1 /* RETableViewOptionCell.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };