6 Commits

Author SHA1 Message Date
Mathias Claassen 6ac31155f8 release 4.0.1 (#1049) 2019-04-15 11:07:06 -03:00
Liraz S 151003d8e5 Memory and stability fixes to XLForm (#1045)
* selectorCell display repair

Unable to display when value than apples first selectorOptions

* fixed crash

* fixed memory leaks

* Cell disappears while inline picker is open

* Fixes crash on update

* check object object equal

* codereview

* fixed memory leaks

* fixed memory leaks [2]

* updated logic

* fixed memory leaks

* fix for crash #1043

* fix for crash #1044

* fix for issue #1044

* fix for issue #1044

* fixed mistake

* fixed observation if lib uses in drawer controller

* fixed kvo crash

* reverted last fix

* cleanup

* fixed kvo

* fix for crash #1043

* reverted https://github.com/xmartlabs/XLForm/pull/1045#discussion_r255965033

* reverted #948

* fixed firstResponder logic

* codereview in Descriptors

* codereview
2019-03-25 12:20:16 -03:00
Mathias Claassen b5bdda8e80 Update Readme (#1046) 2019-03-14 13:40:30 -03:00
Bruno Agatte 81aca9c49c Update XLFormRowDescriptor.m to support <Class>.self for custom cells (#1041) 2019-01-08 10:59:18 -03:00
Ju d8ece1410d Fix crash when using swift custom cells with xib files (#1038) (#1040) 2019-01-07 15:57:31 -03:00
Nikita Razumnuy fdca5f7543 fix: can't update placeholder color using setNeedsDisplay in XLFormTextView (#1024) 2018-08-23 11:20:17 -03:00
47 changed files with 878 additions and 706 deletions
+2 -4
View File
@@ -19,7 +19,5 @@ DerivedData
#CocoaPods
Pods
Tests/Pods
Tests/Podfile.lock
Examples/Objective-C/Podfile.lock
Examples/Swift/Podfile.lock
Podfile.lock
*.xcworkspace
+3 -3
View File
@@ -1,8 +1,8 @@
language: objective-c
osx_image: xcode9
osx_image: xcode10.2
before_install:
- gem install cocoapods --no-rdoc --no-ri --no-document --quiet
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
- gem install cocoapods --quiet
- gem install xcpretty --quiet
- cd Tests && pod install && cd $TRAVIS_BUILD_DIR
script: rake test
+4
View File
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.
### Version 4.0.1:
* Memory improvements and fixes.
* Other minor fixes
### Version 4.0.0:
* Adds support for Xcode 9.
* Deprecated UIAlertView, UIActionSheet, UIPopoverController.
@@ -21,7 +21,7 @@
// http://stackoverflow.com/questions/12580162/nsstring-to-nsdate-conversion-issue
@interface CurrencyFormatter : NSNumberFormatter
@property (readonly) NSDecimalNumberHandler *roundingBehavior;
@property (readonly, strong) NSDecimalNumberHandler *roundingBehavior;
@end
@@ -117,4 +117,4 @@
}
@end
@end
+11 -4
View File
@@ -43,7 +43,7 @@ PODS:
- XLData/RemoteDataStore (2.0.0):
- XLData/CoreRemote
- XLData/DataStore
- XLForm (4.0.0)
- XLForm (4.0.1)
DEPENDENCIES:
- AFNetworking (~> 2.0)
@@ -53,12 +53,19 @@ DEPENDENCIES:
- XLData (from `https://github.com/xmartlabs/XLData.git`, commit `1f9019b56242a2019c7f7e11ec4ef823c397ebcf`)
- XLForm (from `../../`)
SPEC REPOS:
https://github.com/cocoapods/specs.git:
- AFNetworking
- AXRatingView
- JVFloatLabeledTextField
- SHSPhoneComponent
EXTERNAL SOURCES:
XLData:
:commit: 1f9019b56242a2019c7f7e11ec4ef823c397ebcf
:git: https://github.com/xmartlabs/XLData.git
XLForm:
:path: ../../
:path: "../../"
CHECKOUT OPTIONS:
XLData:
@@ -71,8 +78,8 @@ SPEC CHECKSUMS:
JVFloatLabeledTextField: 58a3a32cfb800e5b224f676987e7c13abf50a14d
SHSPhoneComponent: 4cec0653a150ad63cbc52b0c8b29ce2d3c9c26f0
XLData: df725c6179e2e0c80bf56a1ecad9afd169707a6d
XLForm: 04110197c12187dd28a6c7295d3d8b95f4fdb4de
XLForm: b8d47a9a00fb6166981cb40de7169d70d611e9be
PODFILE CHECKSUM: 64fbcd03a2c13762b2c18e3938cc8008807937c9
COCOAPODS: 1.3.1
COCOAPODS: 1.6.0
@@ -486,7 +486,6 @@
2850C5F418D0F706002B7D0A /* Sources */,
2850C5F518D0F706002B7D0A /* Frameworks */,
2850C5F618D0F706002B7D0A /* Resources */,
32EB30E0A90A4E91864B1D3C /* [CP] Embed Pods Frameworks */,
DE3D12F5596780A66C6C3D4A /* [CP] Copy Pods Resources */,
);
buildRules = (
@@ -504,7 +503,7 @@
2850C5F018D0F706002B7D0A /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = Xmartlabs;
};
buildConfigurationList = 2850C5F318D0F706002B7D0A /* Build configuration list for PBXProject "XLForm" */;
@@ -542,37 +541,22 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
32EB30E0A90A4E91864B1D3C /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-XLForm/Pods-XLForm-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
DE3D12F5596780A66C6C3D4A /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-XLForm/Pods-XLForm-resources.sh",
"${PODS_ROOT}/Target Support Files/Pods-XLForm/Pods-XLForm-resources.sh",
"${PODS_ROOT}/../../../XLForm/XLForm.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/XLForm.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-XLForm/Pods-XLForm-resources.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-XLForm/Pods-XLForm-resources.sh\"\n";
showEnvVarsInLog = 0;
};
EBE0335CCC7588D83B89A92A /* [CP] Check Pods Manifest.lock */ = {
@@ -668,12 +652,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -718,12 +704,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
@@ -48,6 +58,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
@@ -101,8 +121,13 @@
"scale" : "2x"
},
{
"idiom" : "car",
"size" : "120x120",
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
},
{
@@ -142,8 +167,15 @@
"size" : "44x44",
"idiom" : "watch",
"scale" : "2x",
"role" : "longLook",
"subtype" : "42mm"
"role" : "appLauncher",
"subtype" : "40mm"
},
{
"size" : "50x50",
"idiom" : "watch",
"scale" : "2x",
"role" : "appLauncher",
"subtype" : "44mm"
},
{
"size" : "86x86",
@@ -158,6 +190,30 @@
"scale" : "2x",
"role" : "quickLook",
"subtype" : "42mm"
},
{
"size" : "108x108",
"idiom" : "watch",
"scale" : "2x",
"role" : "quickLook",
"subtype" : "44mm"
},
{
"idiom" : "watch-marketing",
"size" : "1024x1024",
"scale" : "1x"
},
{
"idiom" : "car",
"size" : "120x120",
"scale" : "1x"
},
{
"size" : "44x44",
"idiom" : "watch",
"scale" : "2x",
"role" : "longLook",
"subtype" : "42mm"
}
],
"info" : {
@@ -17,9 +17,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Declare custom rows
XLFormViewController.cellClassesForRowDescriptorTypes()[XLFormRowDescriptorTypeRate] = "XLFormRatingCell"
XLFormViewController.cellClassesForRowDescriptorTypes()[XLFormRowDescriptorTypeRate] = NSStringFromClass(XLFormRatingCell.self)
XLFormViewController.cellClassesForRowDescriptorTypes()[XLFormRowDescriptorTypeFloatLabeledTextField] = FloatLabeledTextFieldCell.self
XLFormViewController.cellClassesForRowDescriptorTypes()[XLFormRowDescriptorTypeWeekDays] = "XLFormWeekDaysCell"
XLFormViewController.cellClassesForRowDescriptorTypes()[XLFormRowDescriptorTypeWeekDays] = NSStringFromClass(XLFormWeekDaysCell.self)
XLFormViewController.cellClassesForRowDescriptorTypes()[XLFormRowDescriptorTypeSegmentedInline] = InlineSegmentedCell.self
XLFormViewController.cellClassesForRowDescriptorTypes()[XLFormRowDescriptorTypeSegmentedControl] = InlineSegmentedControl.self
XLFormViewController.inlineRowDescriptorTypesForRowDescriptorTypes()[XLFormRowDescriptorTypeSegmentedInline] = XLFormRowDescriptorTypeSegmentedControl
+3 -1
View File
@@ -6,7 +6,9 @@ By [XMARTLABS](http://xmartlabs.com).
[![Build Status](https://travis-ci.org/xmartlabs/XLForm.svg?branch=master)](https://travis-ci.org/xmartlabs/XLForm)
<a href="https://cocoapods.org/pods/XLForm"><img src="https://img.shields.io/cocoapods/v/XLForm.svg" alt="CocoaPods compatible" /></a>
**If you are working in Swift then you should have a look at [Eureka], a complete re-design of XLForm in Swift.** *Do not panic, we will continue maintaining and improving XLForm, obj-c rocks!!*
**If you are working in Swift then you should have a look at [Eureka], a complete re-design of XLForm in Swift and with more features.**
We are not implementing any new features for XLForm anymore. However, if a critical issue arises we will fix it.
Purpose
--------------
+2 -2
View File
@@ -3,7 +3,7 @@ include FileUtils::Verbose
namespace :test do
desc "Run the XLForm Tests"
task :ios do
run_tests('XLForm Tests', 'iphonesimulator11.0')
run_tests('XLForm Tests', 'iphonesimulator12.2')
tests_failed unless $?.success?
end
end
@@ -17,7 +17,7 @@ task :default => 'test'
private
def run_tests(scheme, sdk)
sh("xcodebuild -workspace 'Tests/XLForm Tests.xcworkspace' -scheme '#{scheme}' -sdk '#{sdk}' -destination 'OS=11.0,name=iPhone 8' -configuration Release clean test | xcpretty -c ; exit ${PIPESTATUS[0]}") rescue nil
sh("xcodebuild -workspace 'Tests/XLForm Tests.xcworkspace' -scheme '#{scheme}' -sdk '#{sdk}' -destination 'OS=12.2,name=iPhone 8' -configuration Release clean test | xcpretty -c ; exit ${PIPESTATUS[0]}") rescue nil
end
def tests_failed
+3 -19
View File
@@ -150,7 +150,6 @@
28657A361990879200CE8180 /* Sources */,
28657A371990879200CE8180 /* Frameworks */,
28657A381990879200CE8180 /* Resources */,
51F3E228D166F2E8BF8C889E /* [CP] Embed Pods Frameworks */,
7E96395A3A94BDD9487AE471 /* [CP] Copy Pods Resources */,
);
buildRules = (
@@ -217,37 +216,22 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
51F3E228D166F2E8BF8C889E /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-XLForm Tests/Pods-XLForm Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
7E96395A3A94BDD9487AE471 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-XLForm Tests/Pods-XLForm Tests-resources.sh",
"${PODS_ROOT}/Target Support Files/Pods-XLForm Tests/Pods-XLForm Tests-resources.sh",
"${PODS_ROOT}/../../XLForm/XLForm.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/XLForm.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-XLForm Tests/Pods-XLForm Tests-resources.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-XLForm Tests/Pods-XLForm Tests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'XLForm'
s.version = '4.0.0'
s.version = '4.0.1'
s.license = { :type => 'MIT' }
s.summary = 'XLForm is the most flexible and powerful iOS library to create dynamic table-view forms.'
s.description = <<-DESC
+5 -1
View File
@@ -414,7 +414,7 @@
E267FD171BE8048900F86B42 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = XLForm;
TargetAttributes = {
E267FD1F1BE8048900F86B42 = {
@@ -509,12 +509,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -564,12 +566,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0940"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
@@ -37,7 +36,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
+2 -2
View File
@@ -42,8 +42,8 @@
@protocol XLFormReturnKeyProtocol
@property UIReturnKeyType returnKeyType;
@property UIReturnKeyType nextReturnKeyType;
@property (nonatomic, assign) UIReturnKeyType returnKeyType;
@property (nonatomic, assign) UIReturnKeyType nextReturnKeyType;
@end
+5 -5
View File
@@ -34,10 +34,10 @@ typedef NS_ENUM(NSUInteger, XLFormDateDatePickerMode) {
@interface XLFormDateCell : XLFormBaseCell
@property (nonatomic) XLFormDateDatePickerMode formDatePickerMode;
@property (nonatomic) NSDate *minimumDate;
@property (nonatomic) NSDate *maximumDate;
@property (nonatomic) NSInteger minuteInterval;
@property (nonatomic) NSLocale *locale;
@property (nonatomic, assign) XLFormDateDatePickerMode formDatePickerMode;
@property (nonatomic, copy ) NSDate *minimumDate;
@property (nonatomic, copy ) NSDate *maximumDate;
@property (nonatomic, assign) NSInteger minuteInterval;
@property (nonatomic, copy ) NSLocale *locale;
@end
+6 -11
View File
@@ -37,16 +37,6 @@
return YES;
}
#pragma mark - Properties
-(UIDatePicker *)datePicker
{
if (_datePicker) return _datePicker;
_datePicker = [UIDatePicker autolayoutView];
[_datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
return _datePicker;
}
#pragma mark- Target Action
- (void)datePickerValueChanged:(UIDatePicker *)sender
@@ -66,7 +56,12 @@
-(void)configure
{
[super configure];
[self.contentView addSubview:self.datePicker];
UIDatePicker *datePicker = [UIDatePicker autolayoutView];
[datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.contentView addSubview:datePicker];
_datePicker = datePicker;
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.datePicker attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[datePicker]-0-|" options:0 metrics:0 views:@{@"datePicker" : self.datePicker}]];
}
+4 -3
View File
@@ -71,6 +71,7 @@
- (void)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)controller
{
__weak typeof(self) weak = self;
alertController = [UIAlertController alertControllerWithTitle: self.rowDescriptor.title
message: nil
preferredStyle: UIAlertControllerStyleActionSheet];
@@ -78,14 +79,14 @@
[alertController addAction:[UIAlertAction actionWithTitle: NSLocalizedString(@"Choose From Library", nil)
style: UIAlertActionStyleDefault
handler: ^(UIAlertAction * _Nonnull action) {
[self openImage:UIImagePickerControllerSourceTypePhotoLibrary];
[weak openImage:UIImagePickerControllerSourceTypePhotoLibrary];
}]];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[alertController addAction:[UIAlertAction actionWithTitle: NSLocalizedString(@"Take Photo", nil)
style: UIAlertActionStyleDefault
handler: ^(UIAlertAction * _Nonnull action) {
[self openImage:UIImagePickerControllerSourceTypeCamera];
[weak openImage:UIImagePickerControllerSourceTypeCamera];
}]];
}
@@ -100,7 +101,7 @@
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.formViewController presentViewController:alertController animated: true completion: nil];
[weak.formViewController presentViewController:self->alertController animated: true completion: nil];
});
}
+4 -4
View File
@@ -196,14 +196,14 @@
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil)
style:UIAlertActionStyleCancel
handler:nil]];
__weak __typeof(self)weakSelf = self;
__weak typeof(self) weak = self;
for (XLFormLeftRightSelectorOption * leftOption in self.rowDescriptor.selectorOptions) {
[alertController addAction:[UIAlertAction actionWithTitle:[leftOption.leftValue displayText]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
weakSelf.rowDescriptor.value = [self chooseNewRightValueFromOption:leftOption];
weakSelf.rowDescriptor.leftRightSelectorLeftOptionSelected = [self leftOptionForDescription:[leftOption.leftValue displayText]].leftValue;
[weakSelf.formViewController updateFormRow:weakSelf.rowDescriptor];
weak.rowDescriptor.value = [weak chooseNewRightValueFromOption:leftOption];
weak.rowDescriptor.leftRightSelectorLeftOptionSelected = [weak leftOptionForDescription:[leftOption.leftValue displayText]].leftValue;
[weak.formViewController updateFormRow:weak.rowDescriptor];
}]];
}
+1 -1
View File
@@ -28,6 +28,6 @@
@interface XLFormPickerCell : XLFormBaseCell<XLFormInlineRowDescriptorCell>
@property (nonatomic) UIPickerView * pickerView;
@property (nonatomic, weak) UIPickerView * pickerView;
@end
+8 -12
View File
@@ -56,23 +56,19 @@
return [self formDescriptorCellCanBecomeFirstResponder];
}
#pragma mark - Properties
-(UIPickerView *)pickerView
{
if (_pickerView) return _pickerView;
_pickerView = [UIPickerView autolayoutView];
_pickerView.delegate = self;
_pickerView.dataSource = self;
return _pickerView;
}
#pragma mark - XLFormDescriptorCell
-(void)configure
{
[super configure];
[self.contentView addSubview:self.pickerView];
UIPickerView *pickerView = [UIPickerView autolayoutView];
pickerView.delegate = self;
pickerView.dataSource = self;
[self.contentView addSubview:pickerView];
_pickerView = pickerView;
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.pickerView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[pickerView]-0-|" options:0 metrics:0 views:@{@"pickerView" : self.pickerView}]];
}
+4 -1
View File
@@ -30,7 +30,7 @@
@interface XLFormSegmentedCell()
@property NSMutableArray * dynamicCustomConstraints;
@property (nonatomic, strong) NSMutableArray * dynamicCustomConstraints;
@end
@@ -168,6 +168,9 @@
-(void)dealloc
{
[self.textLabel removeObserver:self forKeyPath:@"text"];
[self.dynamicCustomConstraints removeAllObjects];
self.dynamicCustomConstraints = nil;
}
@end
+4 -4
View File
@@ -31,10 +31,10 @@ extern NSString *const XLFormTextFieldMaxNumberOfCharacters;
@interface XLFormTextFieldCell : XLFormBaseCell <XLFormReturnKeyProtocol>
@property (nonatomic, readonly) UILabel * textLabel;
@property (nonatomic, readonly) UITextField * textField;
@property (nonatomic, readonly, weak) UILabel * textLabel;
@property (nonatomic, readonly, weak) UITextField * textField;
@property (nonatomic) NSNumber *textFieldLengthPercentage;
@property (nonatomic) NSNumber *textFieldMaxNumberOfCharacters;
@property (nonatomic, copy) NSNumber *textFieldLengthPercentage;
@property (nonatomic, copy) NSNumber *textFieldMaxNumberOfCharacters;
@end
+20 -24
View File
@@ -34,7 +34,7 @@ NSString *const XLFormTextFieldMaxNumberOfCharacters = @"textFieldMaxNumberOfCha
@interface XLFormTextFieldCell() <UITextFieldDelegate>
@property NSMutableArray * dynamicCustomConstraints;
@property (nonatomic, strong) NSMutableArray * dynamicCustomConstraints;
@end
@@ -69,8 +69,14 @@ NSString *const XLFormTextFieldMaxNumberOfCharacters = @"textFieldMaxNumberOfCha
-(void)dealloc
{
[self.textField removeTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[self.textLabel removeObserver:self forKeyPath:@"text"];
[self.imageView removeObserver:self forKeyPath:@"image"];
self.textField.delegate = nil;
[self.dynamicCustomConstraints removeAllObjects];
self.dynamicCustomConstraints = nil;
}
#pragma mark - XLFormDescriptorCell
@@ -79,8 +85,14 @@ NSString *const XLFormTextFieldMaxNumberOfCharacters = @"textFieldMaxNumberOfCha
{
[super configure];
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
[self.contentView addSubview:self.textLabel];
[self.contentView addSubview:self.textField];
UILabel *textLabel = [UILabel autolayoutView];
[self.contentView addSubview:textLabel];
_textLabel = textLabel;
UITextField *textField = [UITextField autolayoutView];
[self.contentView addSubview:textField];
_textField = textField;
[self.contentView addConstraints:[self layoutConstraints]];
[self.textLabel addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
[self.imageView addObserver:self forKeyPath:@"image" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
@@ -176,22 +188,6 @@ NSString *const XLFormTextFieldMaxNumberOfCharacters = @"textFieldMaxNumberOfCha
[self.formViewController updateFormRow:self.rowDescriptor];
}
#pragma mark - Properties
-(UILabel *)textLabel
{
if (_textLabel) return _textLabel;
_textLabel = [UILabel autolayoutView];
return _textLabel;
}
-(UITextField *)textField
{
if (_textField) return _textField;
_textField = [UITextField autolayoutView];
return _textField;
}
#pragma mark - LayoutConstraints
-(NSArray *)layoutConstraints
@@ -225,10 +221,10 @@ NSString *const XLFormTextFieldMaxNumberOfCharacters = @"textFieldMaxNumberOfCha
self.dynamicCustomConstraints = [NSMutableArray arrayWithArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[image]-[label]-[textField]-|" options:0 metrics:nil views:views]];
[self.dynamicCustomConstraints addObject:[NSLayoutConstraint constraintWithItem:_textField
attribute:NSLayoutAttributeWidth
relatedBy:self.textFieldLengthPercentage ? NSLayoutRelationEqual : NSLayoutRelationGreaterThanOrEqual
relatedBy:self.textFieldLengthPercentage != nil ? NSLayoutRelationEqual : NSLayoutRelationGreaterThanOrEqual
toItem:self.contentView
attribute:NSLayoutAttributeWidth
multiplier:self.textFieldLengthPercentage ? [self.textFieldLengthPercentage floatValue] : 0.3
multiplier:self.textFieldLengthPercentage != nil ? [self.textFieldLengthPercentage floatValue] : 0.3
constant:0.0]];
}
else{
@@ -240,10 +236,10 @@ NSString *const XLFormTextFieldMaxNumberOfCharacters = @"textFieldMaxNumberOfCha
self.dynamicCustomConstraints = [NSMutableArray arrayWithArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[label]-[textField]-|" options:0 metrics:nil views:views]];
[self.dynamicCustomConstraints addObject:[NSLayoutConstraint constraintWithItem:_textField
attribute:NSLayoutAttributeWidth
relatedBy:self.textFieldLengthPercentage ? NSLayoutRelationEqual : NSLayoutRelationGreaterThanOrEqual
relatedBy:self.textFieldLengthPercentage != nil ? NSLayoutRelationEqual : NSLayoutRelationGreaterThanOrEqual
toItem:self.contentView
attribute:NSLayoutAttributeWidth
multiplier:self.textFieldLengthPercentage ? [self.textFieldLengthPercentage floatValue] : 0.3
multiplier:self.textFieldLengthPercentage != nil ? [self.textFieldLengthPercentage floatValue] : 0.3
constant:0.0]];
}
else{
@@ -279,7 +275,7 @@ NSString *const XLFormTextFieldMaxNumberOfCharacters = @"textFieldMaxNumberOfCha
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (self.textFieldMaxNumberOfCharacters) {
if (self.textFieldMaxNumberOfCharacters != nil) {
// Check maximum length requirement
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (newString.length > self.textFieldMaxNumberOfCharacters.integerValue) {
+4 -4
View File
@@ -33,10 +33,10 @@ extern NSString *const XLFormTextViewMaxNumberOfCharacters;
@interface XLFormTextViewCell : XLFormBaseCell
@property (nonatomic, readonly) UILabel * label DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("Use textLabel instead");
@property (nonatomic, readonly) UILabel * textLabel;
@property (nonatomic, readonly) XLFormTextView * textView;
@property (nonatomic, readonly, weak) UILabel * textLabel;
@property (nonatomic, readonly, weak) XLFormTextView * textView;
@property (nonatomic) NSNumber *textViewLengthPercentage;
@property (nonatomic) NSNumber *textViewMaxNumberOfCharacters;
@property (nonatomic, copy) NSNumber *textViewLengthPercentage;
@property (nonatomic, copy) NSNumber *textViewMaxNumberOfCharacters;
@end
+11 -19
View File
@@ -70,34 +70,26 @@ NSString *const XLFormTextViewMaxNumberOfCharacters = @"textViewMaxNumberOfChara
#pragma mark - Properties
-(UILabel *)textLabel
{
if (_textLabel) return _textLabel;
_textLabel = [UILabel autolayoutView];
[_textLabel setContentHuggingPriority:500 forAxis:UILayoutConstraintAxisHorizontal];
return _textLabel;
}
-(UILabel *)label
{
return self.textLabel;
}
-(XLFormTextView *)textView
{
if (_textView) return _textView;
_textView = [XLFormTextView autolayoutView];
return _textView;
}
#pragma mark - XLFormDescriptorCell
-(void)configure
{
[super configure];
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
[self.contentView addSubview:self.textLabel];
[self.contentView addSubview:self.textView];
UILabel *textLabel = [UILabel autolayoutView];
[textLabel setContentHuggingPriority:500 forAxis:UILayoutConstraintAxisHorizontal];
[self.contentView addSubview:textLabel];
_textLabel = textLabel;
XLFormTextView *textView = [XLFormTextView autolayoutView];
[self.contentView addSubview:textView];
_textView = textView;
[self.textLabel addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
NSDictionary * views = @{@"label": self.textLabel, @"textView": self.textView};
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-8-[label]" options:0 metrics:0 views:views]];
@@ -160,7 +152,7 @@ NSString *const XLFormTextViewMaxNumberOfCharacters = @"textViewMaxNumberOfChara
}
else{
[_dynamicCustomConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[label]-[textView]-|" options:0 metrics:0 views:views]];
if (self.textViewLengthPercentage) {
if (self.textViewLengthPercentage != nil) {
[_dynamicCustomConstraints addObject:[NSLayoutConstraint constraintWithItem:_textView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
@@ -207,7 +199,7 @@ NSString *const XLFormTextViewMaxNumberOfCharacters = @"textViewMaxNumberOfChara
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if (self.textViewMaxNumberOfCharacters) {
if (self.textViewMaxNumberOfCharacters != nil) {
// Check maximum length requirement
NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
if (newText.length > self.textViewMaxNumberOfCharacters.integerValue) {
+2 -2
View File
@@ -28,8 +28,8 @@
@interface XLFormOptionsObject : NSObject <XLFormOptionObject,NSCoding>
@property (nonatomic) NSString * formDisplaytext;
@property (nonatomic) id formValue;
@property (nonatomic, copy) NSString * formDisplaytext;
@property (nonatomic, strong) id formValue;
+(XLFormOptionsObject *)formOptionsObjectWithValue:(id)value displayText:(NSString *)displayText;
+(XLFormOptionsObject *)formOptionsOptionForValue:(id)value fromOptions:(NSArray *)options;
@@ -107,4 +107,9 @@
}
-(NSUInteger)hash
{
return [[self formValue ] hash];
}
@end
@@ -34,8 +34,8 @@
@interface XLFormOptionsViewController () <UITableViewDataSource>
@property NSString * titleHeaderSection;
@property NSString * titleFooterSection;
@property (nonatomic, copy) NSString * titleHeaderSection;
@property (nonatomic, copy) NSString * titleFooterSection;
@end
@@ -30,6 +30,6 @@
@protocol XLFormRowDescriptorViewController <NSObject>
@required
@property (nonatomic) XLFormRowDescriptor * rowDescriptor;
@property (nonatomic, weak) XLFormRowDescriptor * rowDescriptor;
@end
+2 -2
View File
@@ -81,8 +81,8 @@ typedef NS_ENUM(NSUInteger, XLFormRowNavigationDirection) {
@interface XLFormViewController : UIViewController<UITableViewDataSource, UITableViewDelegate, XLFormDescriptorDelegate, UITextFieldDelegate, UITextViewDelegate, XLFormViewControllerDelegate>
@property XLFormDescriptor * form;
@property IBOutlet UITableView * tableView;
@property (nonatomic, strong) XLFormDescriptor * form;
@property (nonatomic, weak) IBOutlet UITableView * tableView;
-(instancetype)initWithForm:(XLFormDescriptor *)form;
-(instancetype)initWithForm:(XLFormDescriptor *)form style:(UITableViewStyle)style;
+80 -59
View File
@@ -33,7 +33,6 @@
@interface XLFormRowDescriptor(_XLFormViewController)
@property (readonly) NSArray * observers;
-(BOOL)evaluateIsDisabled;
-(BOOL)evaluateIsHidden;
@@ -47,7 +46,7 @@
@interface XLFormDescriptor (_XLFormViewController)
@property NSMutableDictionary* rowObservers;
@property (atomic, strong) NSMutableDictionary* rowObservers;
@end
@@ -57,8 +56,8 @@
NSNumber *_oldBottomTableContentInset;
CGRect _keyboardFrame;
}
@property UITableViewStyle tableViewStyle;
@property (nonatomic) XLFormRowNavigationAccessoryView * navigationAccessoryView;
@property (nonatomic, assign) UITableViewStyle tableViewStyle;
@property (nonatomic, strong) XLFormRowNavigationAccessoryView * navigationAccessoryView;
@end
@@ -104,25 +103,34 @@
return self;
}
- (void)dealloc
-(void)dealloc
{
[self removeObserverFromController];
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
self.form.delegate = nil;
self.navigationAccessoryView = nil;
}
- (void)viewDidLoad
-(void)viewDidLoad
{
[super viewDidLoad];
if (!self.tableView){
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds
UITableView *tableView = self.tableView;
if (!tableView){
tableView = [[UITableView alloc] initWithFrame:self.view.bounds
style:self.tableViewStyle];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
if([self.tableView respondsToSelector:@selector(cellLayoutMarginsFollowReadableWidth)]){
self.tableView.cellLayoutMarginsFollowReadableWidth = NO;
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
if([tableView respondsToSelector:@selector(cellLayoutMarginsFollowReadableWidth)]){
tableView.cellLayoutMarginsFollowReadableWidth = NO;
}
}
if (!self.tableView.superview){
[self.view addSubview:self.tableView];
if (!tableView.superview){
[self.view addSubview:tableView];
self.tableView = tableView;
}
if (!self.tableView.delegate){
self.tableView.delegate = self;
@@ -147,44 +155,18 @@
{
[super viewWillAppear:animated];
NSIndexPath *selected = [self.tableView indexPathForSelectedRow];
if (selected){
if (selected) {
// Trigger a cell refresh
XLFormRowDescriptor * rowDescriptor = [self.form formRowAtIndex:selected];
[self updateFormRow:rowDescriptor];
[self.tableView selectRowAtIndexPath:selected animated:NO scrollPosition:UITableViewScrollPositionNone];
[self.tableView deselectRowAtIndexPath:selected animated:YES];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(contentSizeCategoryChanged:)
name:UIContentSizeCategoryDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
[self addObserverToController];
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIContentSizeCategoryDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)viewDidAppear:(BOOL)animated
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (self.form.assignFirstResponderOnShow) {
@@ -193,11 +175,40 @@
}
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self removeObserverFromController];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(void)addObserverToController {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(contentSizeCategoryChanged:)
name:UIContentSizeCategoryDidChangeNotification
object:nil];
[nc addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[nc addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
-(void)removeObserverFromController {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self name:UIContentSizeCategoryDidChangeNotification object:nil];
[nc removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[nc removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
#pragma mark - CellClasses
+(NSMutableDictionary *)cellClassesForRowDescriptorTypes
@@ -314,8 +325,8 @@
-(void)updateAfterDependentRowChanged:(XLFormRowDescriptor *)formRow
{
NSMutableArray* revaluateHidden = self.form.rowObservers[[formRow.tag formKeyForPredicateType:XLPredicateTypeHidden]];
NSMutableArray* revaluateDisabled = self.form.rowObservers[[formRow.tag formKeyForPredicateType:XLPredicateTypeDisabled]];
NSMutableArray* revaluateHidden = [self.form.rowObservers[[formRow.tag formKeyForPredicateType:XLPredicateTypeHidden]] mutableCopy];
NSMutableArray* revaluateDisabled = [self.form.rowObservers[[formRow.tag formKeyForPredicateType:XLPredicateTypeDisabled]] mutableCopy];
for (id object in revaluateDisabled) {
if ([object isKindOfClass:[NSString class]]) {
XLFormRowDescriptor* row = [self.form formRowWithTag:object];
@@ -434,9 +445,10 @@
XLFormSectionDescriptor * multivaluedFormSection = formRow.sectionDescriptor;
XLFormRowDescriptor * formRowDescriptor = [self formRowFormMultivaluedFormSection:multivaluedFormSection];
[multivaluedFormSection addFormRow:formRowDescriptor];
__weak typeof(self) weak = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.tableView.editing = !self.tableView.editing;
self.tableView.editing = !self.tableView.editing;
weak.tableView.editing = !weak.tableView.editing;
weak.tableView.editing = !weak.tableView.editing;
});
UITableViewCell<XLFormDescriptorCell> * cell = (UITableViewCell<XLFormDescriptorCell> *)[formRowDescriptor cellForFormController:self];
if ([cell formDescriptorCellCanBecomeFirstResponder]){
@@ -568,18 +580,24 @@
-(XLFormBaseCell *)updateFormRow:(XLFormRowDescriptor *)formRow
{
XLFormBaseCell * cell = [formRow cellForFormController:self];
[self configureCell:cell];
[cell setNeedsUpdateConstraints];
[cell setNeedsLayout];
if (cell != nil) {
[self configureCell:cell];
[cell setNeedsUpdateConstraints];
[cell setNeedsLayout];
}
return cell;
}
-(void)configureCell:(XLFormBaseCell*) cell
{
[cell update];
[cell.rowDescriptor.cellConfig enumerateKeysAndObjectsUsingBlock:^(NSString *keyPath, id value, BOOL * __unused stop) {
[cell setValue:(value == [NSNull null]) ? nil : value forKeyPath:keyPath];
}];
if(cell.rowDescriptor != nil && cell.rowDescriptor.cellConfig != nil) {
[cell.rowDescriptor.cellConfig enumerateKeysAndObjectsUsingBlock:^(NSString *keyPath, id value, BOOL * __unused stop) {
[cell setValue:(value == [NSNull null]) ? nil : value forKeyPath:keyPath];
}];
}
if (cell.rowDescriptor.isDisabled){
[cell.rowDescriptor.cellConfigIfDisabled enumerateKeysAndObjectsUsingBlock:^(NSString *keyPath, id value, BOOL * __unused stop) {
[cell setValue:(value == [NSNull null]) ? nil : value forKeyPath:keyPath];
@@ -650,9 +668,10 @@
#pragma GCC diagnostic pop
// update the accessory view
[self inputAccessoryViewForRowDescriptor:row];
__weak typeof(self) weak = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.tableView.editing = !self.tableView.editing;
self.tableView.editing = !self.tableView.editing;
weak.tableView.editing = !weak.tableView.editing;
weak.tableView.editing = !weak.tableView.editing;
});
}
@@ -667,9 +686,10 @@
[self.tableView endEditing:YES];
}
[multivaluedFormRow.sectionDescriptor removeFormRowAtIndex:indexPath.row];
__weak typeof(self) weak = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.tableView.editing = !self.tableView.editing;
self.tableView.editing = !self.tableView.editing;
weak.tableView.editing = !weak.tableView.editing;
weak.tableView.editing = !weak.tableView.editing;
});
if (firstResponder){
UITableViewCell<XLFormDescriptorCell> * firstResponderCell = [firstResponder formDescriptorCell];
@@ -686,9 +706,10 @@
else{
XLFormRowDescriptor * formRowDescriptor = [self formRowFormMultivaluedFormSection:multivaluedFormSection];
[multivaluedFormSection addFormRow:formRowDescriptor];
__weak typeof(self) weak = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.tableView.editing = !self.tableView.editing;
self.tableView.editing = !self.tableView.editing;
weak.tableView.editing = !weak.tableView.editing;
weak.tableView.editing = !weak.tableView.editing;
});
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
UITableViewCell<XLFormDescriptorCell> * cell = (UITableViewCell<XLFormDescriptorCell> *)[formRowDescriptor cellForFormController:self];
+8 -8
View File
@@ -49,15 +49,15 @@ typedef NS_OPTIONS(NSUInteger, XLFormRowNavigationOptions) {
@interface XLFormDescriptor : NSObject
@property (readonly, nonatomic, nonnull) NSMutableArray * formSections;
@property (readonly, nullable) NSString * title;
@property (nonatomic) BOOL endEditingTableViewOnScroll;
@property (nonatomic) BOOL assignFirstResponderOnShow;
@property (nonatomic) BOOL addAsteriskToRequiredRowsTitle;
@property (getter=isDisabled) BOOL disabled;
@property (nonatomic) XLFormRowNavigationOptions rowNavigationOptions;
@property (nonatomic, strong, readonly, nonnull) NSMutableArray * formSections;
@property (nonatomic, readonly, nullable, copy) NSString * title;
@property (nonatomic, assign) BOOL endEditingTableViewOnScroll;
@property (nonatomic, assign) BOOL assignFirstResponderOnShow;
@property (nonatomic, assign) BOOL addAsteriskToRequiredRowsTitle;
@property (nonatomic, getter=isDisabled, assign) BOOL disabled;
@property (nonatomic, assign) XLFormRowNavigationOptions rowNavigationOptions;
@property (weak, nullable) id<XLFormDescriptorDelegate> delegate;
@property (nonatomic, weak, nullable) id<XLFormDescriptorDelegate> delegate;
+(nonnull instancetype)formDescriptor;
+(nonnull instancetype)formDescriptorWithTitle:(nullable NSString *)title;
+204 -153
View File
@@ -32,10 +32,13 @@
NSString * const XLFormErrorDomain = @"XLFormErrorDomain";
NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
NSString * const XLFormSectionsKey = @"formSections";
@interface XLFormSectionDescriptor (_XLFormDescriptor)
@property NSArray * allRows;
@property (nonatomic, weak) NSArray *allRows;
-(BOOL)evaluateIsHidden;
@end
@@ -51,11 +54,11 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
@interface XLFormDescriptor()
@property NSMutableArray * formSections;
@property (readonly) NSMutableArray * allSections;
@property NSString * title;
@property (readonly) NSMutableDictionary* allRowsByTag;
@property NSMutableDictionary* rowObservers;
@property (nonatomic, strong) NSMutableArray *formSections;
@property (nonatomic, strong, readonly) NSMutableArray *allSections;
@property (nonatomic, copy ) NSString *title;
@property (nonatomic, strong, readonly) NSMutableDictionary *allRowsByTag;
@property (atomic , strong) NSMutableDictionary *rowObservers;
@end
@@ -63,15 +66,14 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
-(instancetype)init
{
return [self initWithTitle:nil];
return [self initWithTitle:@""];
}
-(instancetype)initWithTitle:(NSString *)title;
{
self = [super init];
if (self){
if (self = [super init]) {
_formSections = [NSMutableArray array];
_allSections = [NSMutableArray array];
_allSections = [NSMutableArray array];
_allRowsByTag = [NSMutableDictionary dictionary];
_rowObservers = [NSMutableDictionary dictionary];
_title = title;
@@ -79,14 +81,19 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
_disabled = NO;
_endEditingTableViewOnScroll = YES;
_rowNavigationOptions = XLFormRowNavigationOptionEnabled;
[self addObserver:self forKeyPath:@"formSections" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:0];
[self addObserver:self
forKeyPath:XLFormSectionsKey
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
context:0];
}
return self;
}
+(instancetype)formDescriptor
{
return [[self class] formDescriptorWithTitle:nil];
return [[self class] formDescriptorWithTitle:@""];
}
+(instancetype)formDescriptorWithTitle:(NSString *)title
@@ -101,11 +108,11 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
-(void)addFormSection:(XLFormSectionDescriptor *)formSection atIndex:(NSUInteger)index
{
if (index == 0){
if (index == 0) {
[self insertObject:formSection inAllSectionsAtIndex:0];
}
else{
XLFormSectionDescriptor* previousSection = [self.formSections objectAtIndex:MIN(self.formSections.count, index-1)];
else {
XLFormSectionDescriptor *previousSection = [self.formSections objectAtIndex:MIN(self.formSections.count, index-1)];
[self addFormSection:formSection afterSection:previousSection];
}
}
@@ -114,26 +121,28 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
{
NSUInteger sectionIndex;
NSUInteger allSectionIndex;
if ((sectionIndex = [self.allSections indexOfObject:formSection]) == NSNotFound){
if ((sectionIndex = [self.allSections indexOfObject:formSection]) == NSNotFound) {
allSectionIndex = [self.allSections indexOfObject:afterSection];
if (allSectionIndex != NSNotFound) {
[self insertObject:formSection inAllSectionsAtIndex:(allSectionIndex + 1)];
}
else { //case when afterSection does not exist. Just insert at the end.
[self addFormSection:formSection];
return;
}
}
formSection.hidden = formSection.hidden;
}
-(void)addFormRow:(XLFormRowDescriptor *)formRow beforeRow:(XLFormRowDescriptor *)beforeRow
{
if (beforeRow.sectionDescriptor){
if (beforeRow.sectionDescriptor) {
[beforeRow.sectionDescriptor addFormRow:formRow beforeRow:beforeRow];
}
else{
else {
[[self.allSections lastObject] addFormRow:formRow beforeRow:beforeRow];
}
}
@@ -144,27 +153,25 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
[self addFormRow:formRow beforeRow:beforeRowForm];
}
-(void)addFormRow:(XLFormRowDescriptor *)formRow afterRow:(XLFormRowDescriptor *)afterRow
{
if (afterRow.sectionDescriptor){
if (afterRow.sectionDescriptor) {
[afterRow.sectionDescriptor addFormRow:formRow afterRow:afterRow];
}
else{
else {
[[self.allSections lastObject] addFormRow:formRow afterRow:afterRow];
}
}
-(void)addFormRow:(XLFormRowDescriptor *)formRow afterRowTag:(NSString *)afterRowTag
{
XLFormRowDescriptor * afterRowForm = [self formRowWithTag:afterRowTag];
XLFormRowDescriptor *afterRowForm = [self formRowWithTag:afterRowTag];
[self addFormRow:formRow afterRow:afterRowForm];
}
-(void)removeFormSectionAtIndex:(NSUInteger)index
{
if (self.formSections.count > index){
if (self.formSections.count > index) {
XLFormSectionDescriptor *formSection = [self.formSections objectAtIndex:index];
[self removeObjectFromFormSectionsAtIndex:index];
NSUInteger allSectionIndex = [self.allSections indexOfObject:formSection];
@@ -175,43 +182,47 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
-(void)removeFormSection:(XLFormSectionDescriptor *)formSection
{
NSUInteger index = NSNotFound;
if ((index = [self.formSections indexOfObject:formSection]) != NSNotFound){
if ((index = [self.formSections indexOfObject:formSection]) != NSNotFound) {
[self removeFormSectionAtIndex:index];
}
else if ((index = [self.allSections indexOfObject:formSection]) != NSNotFound){
if ((index = [self.allSections indexOfObject:formSection]) != NSNotFound) {
[self removeObjectFromAllSectionsAtIndex:index];
};
}
}
-(void)removeFormRow:(XLFormRowDescriptor *)formRow
{
for (XLFormSectionDescriptor * section in self.formSections){
if ([section.formRows containsObject:formRow]){
for (XLFormSectionDescriptor *section in self.formSections) {
if ([section.formRows containsObject:formRow]) {
[section removeFormRow:formRow];
break;
}
}
}
-(void)showFormSection:(XLFormSectionDescriptor*)formSection
-(void)showFormSection:(XLFormSectionDescriptor *)formSection
{
NSUInteger formIndex = [self.formSections indexOfObject:formSection];
if (formIndex != NSNotFound) {
return;
}
NSUInteger index = [self.allSections indexOfObject:formSection];
if (index != NSNotFound){
if (index != NSNotFound) {
while (formIndex == NSNotFound && index > 0) {
XLFormSectionDescriptor* previous = [self.allSections objectAtIndex:--index];
formIndex = [self.formSections indexOfObject:previous];
}
[self insertObject:formSection inFormSectionsAtIndex:(formIndex == NSNotFound ? 0 : ++formIndex)];
}
}
-(void)hideFormSection:(XLFormSectionDescriptor*)formSection
-(void)hideFormSection:(XLFormSectionDescriptor *)formSection
{
NSUInteger index = [self.formSections indexOfObject:formSection];
if (index != NSNotFound){
if (index != NSNotFound) {
[self removeObjectFromFormSectionsAtIndex:index];
}
}
@@ -224,28 +235,29 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
-(XLFormRowDescriptor *)formRowWithHash:(NSUInteger)hash
{
for (XLFormSectionDescriptor * section in self.allSections){
for (XLFormRowDescriptor * row in section.allRows) {
if ([row hash] == hash){
for (XLFormSectionDescriptor *section in self.allSections) {
for (XLFormRowDescriptor *row in section.allRows) {
if ([row hash] == hash) {
return row;
}
}
}
return nil;
}
-(void)removeFormRowWithTag:(NSString *)tag
{
XLFormRowDescriptor * formRow = [self formRowWithTag:tag];
XLFormRowDescriptor *formRow = [self formRowWithTag:tag];
[self removeFormRow:formRow];
}
-(XLFormRowDescriptor *)formRowAtIndex:(NSIndexPath *)indexPath
{
if ((self.formSections.count > indexPath.section) && [[self.formSections objectAtIndex:indexPath.section] formRows].count > indexPath.row){
if ((self.formSections.count > indexPath.section) && [[self.formSections objectAtIndex:indexPath.section] formRows].count > indexPath.row) {
return [[[self.formSections objectAtIndex:indexPath.section] formRows] objectAtIndex:indexPath.row];
}
return nil;
}
@@ -256,55 +268,62 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
-(NSIndexPath *)indexPathOfFormRow:(XLFormRowDescriptor *)formRow
{
XLFormSectionDescriptor * section = formRow.sectionDescriptor;
if (section){
NSIndexPath *result = nil;
XLFormSectionDescriptor *section = formRow.sectionDescriptor;
if (section) {
NSUInteger sectionIndex = [self.formSections indexOfObject:section];
if (sectionIndex != NSNotFound){
if (sectionIndex != NSNotFound) {
NSUInteger rowIndex = [section.formRows indexOfObject:formRow];
if (rowIndex != NSNotFound){
return [NSIndexPath indexPathForRow:rowIndex inSection:sectionIndex];
if (rowIndex != NSNotFound) {
result = [NSIndexPath indexPathForRow:rowIndex inSection:sectionIndex];
}
}
}
return nil;
return result;
}
-(NSIndexPath *)globalIndexPathOfFormRow:(XLFormRowDescriptor *)formRow
{
XLFormSectionDescriptor * section = formRow.sectionDescriptor;
if (section){
NSIndexPath *result = nil;
XLFormSectionDescriptor *section = formRow.sectionDescriptor;
if (section) {
NSUInteger sectionIndex = [self.allSections indexOfObject:section];
if (sectionIndex != NSNotFound){
if (sectionIndex != NSNotFound) {
NSUInteger rowIndex = [section.allRows indexOfObject:formRow];
if (rowIndex != NSNotFound){
return [NSIndexPath indexPathForRow:rowIndex inSection:sectionIndex];
if (rowIndex != NSNotFound) {
result = [NSIndexPath indexPathForRow:rowIndex inSection:sectionIndex];
}
}
}
return nil;
return result;
}
-(NSDictionary *)formValues
{
NSMutableDictionary * result = [NSMutableDictionary dictionary];
for (XLFormSectionDescriptor * section in self.formSections) {
if (section.multivaluedTag.length > 0){
NSMutableArray * multiValuedValuesArray = [NSMutableArray new];
for (XLFormRowDescriptor * row in section.formRows) {
if (row.value){
NSMutableDictionary *result = [NSMutableDictionary dictionary];
for (XLFormSectionDescriptor *section in self.formSections) {
if (section.multivaluedTag.length > 0) {
NSMutableArray *multiValuedValuesArray = [NSMutableArray new];
for (XLFormRowDescriptor *row in section.formRows) {
if (row.value && row.value != [NSNull null]) {
[multiValuedValuesArray addObject:row.value];
}
}
[result setObject:multiValuedValuesArray forKey:section.multivaluedTag];
}
else{
for (XLFormRowDescriptor * row in section.formRows) {
if (row.tag.length > 0){
[result setObject:(row.value ?: [NSNull null]) forKey:row.tag];
else {
for (XLFormRowDescriptor *row in section.formRows) {
id value = [row.value valueData];
if (row.tag.length > 0 && value != nil) {
[result setObject:value forKey:row.tag];
}
}
}
}
return result;
}
@@ -312,49 +331,55 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
{
NSMutableDictionary * result = [NSMutableDictionary dictionary];
for (XLFormSectionDescriptor * section in self.formSections) {
if (section.multivaluedTag.length > 0){
NSMutableArray * multiValuedValuesArray = [NSMutableArray new];
if (section.multivaluedTag.length > 0) {
NSMutableArray *multiValuedValuesArray = [NSMutableArray new];
for (XLFormRowDescriptor * row in section.formRows) {
if ([row.value valueData]){
if ([row.value valueData]) {
[multiValuedValuesArray addObject:[row.value valueData]];
}
}
[result setObject:multiValuedValuesArray forKey:section.multivaluedTag];
}
else{
else {
for (XLFormRowDescriptor * row in section.formRows) {
NSString * httpParameterKey = nil;
if ((httpParameterKey = [self httpParameterKeyForRow:row cell:[row cellForFormController:formViewController]])){
NSString *httpParameterKey = nil;
if ((httpParameterKey = [self httpParameterKeyForRow:row cell:[row cellForFormController:formViewController]])) {
id parameterValue = [row.value valueData] ?: [NSNull null];
[result setObject:parameterValue forKey:httpParameterKey];
}
}
}
}
return result;
}
-(NSString *)httpParameterKeyForRow:(XLFormRowDescriptor *)row cell:(UITableViewCell<XLFormDescriptorCell> *)descriptorCell
{
if ([descriptorCell respondsToSelector:@selector(formDescriptorHttpParameterName)]){
return [descriptorCell formDescriptorHttpParameterName];
NSString *result = nil;
if ([descriptorCell respondsToSelector:@selector(formDescriptorHttpParameterName)]) {
result = [descriptorCell formDescriptorHttpParameterName];
}
if (row.tag.length > 0){
return row.tag;
else if (row.tag.length > 0) {
result = row.tag;
}
return nil;
return result;
}
-(NSArray *)localValidationErrors:(XLFormViewController *)formViewController {
NSMutableArray * result = [NSMutableArray array];
for (XLFormSectionDescriptor * section in self.formSections) {
for (XLFormRowDescriptor * row in section.formRows) {
XLFormValidationStatus* status = [row doValidation];
-(NSArray *)localValidationErrors:(XLFormViewController *)formViewController
{
NSMutableArray *result = [NSMutableArray array];
for (XLFormSectionDescriptor *section in self.formSections) {
for (XLFormRowDescriptor *row in section.formRows) {
XLFormValidationStatus *status = [row doValidation];
if (status != nil && (![status isValid])) {
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: status.msg,
XLValidationStatusErrorKey: status };
NSError * error = [[NSError alloc] initWithDomain:XLFormErrorDomain code:XLFormErrorCodeGen userInfo:userInfo];
if (error){
NSError *error = [[NSError alloc] initWithDomain:XLFormErrorDomain code:XLFormErrorCodeGen userInfo:userInfo];
if (error) {
[result addObject:error];
}
}
@@ -367,11 +392,11 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
- (void)setFirstResponder:(XLFormViewController *)formViewController
{
for (XLFormSectionDescriptor * formSection in self.formSections) {
for (XLFormRowDescriptor * row in formSection.formRows) {
UITableViewCell<XLFormDescriptorCell> * cell = [row cellForFormController:formViewController];
if ([cell formDescriptorCellCanBecomeFirstResponder]){
if ([cell formDescriptorCellBecomeFirstResponder]){
for (XLFormSectionDescriptor *formSection in self.formSections) {
for (XLFormRowDescriptor *row in formSection.formRows) {
UITableViewCell<XLFormDescriptorCell> *cell = [row cellForFormController:formViewController];
if ([cell formDescriptorCellCanBecomeFirstResponder]) {
if ([cell formDescriptorCellBecomeFirstResponder]) {
return;
}
}
@@ -382,18 +407,23 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
#pragma mark - KVO
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- (void)observeValueForKeyPath:(nullable NSString *)keyPath
ofObject:(nullable id)object
change:(nullable NSDictionary<NSKeyValueChangeKey, id> *)change
context:(nullable void *)context
{
if (!self.delegate) return;
if ([keyPath isEqualToString:@"formSections"]){
if ([[change objectForKey:NSKeyValueChangeKindKey] isEqualToNumber:@(NSKeyValueChangeInsertion)]){
NSIndexSet * indexSet = [change objectForKey:NSKeyValueChangeIndexesKey];
XLFormSectionDescriptor * section = [self.formSections objectAtIndex:indexSet.firstIndex];
if (!self.delegate) {
return;
}
else if ([keyPath isEqualToString:XLFormSectionsKey]) {
if ([[change objectForKey:NSKeyValueChangeKindKey] isEqualToNumber:@(NSKeyValueChangeInsertion)]) {
NSIndexSet *indexSet = [change objectForKey:NSKeyValueChangeIndexesKey];
XLFormSectionDescriptor *section = [self.formSections objectAtIndex:indexSet.firstIndex];
[self.delegate formSectionHasBeenAdded:section atIndex:indexSet.firstIndex];
}
else if ([[change objectForKey:NSKeyValueChangeKindKey] isEqualToNumber:@(NSKeyValueChangeRemoval)]){
NSIndexSet * indexSet = [change objectForKey:NSKeyValueChangeIndexesKey];
XLFormSectionDescriptor * removedSection = [[change objectForKey:NSKeyValueChangeOldKey] objectAtIndex:0];
else if ([[change objectForKey:NSKeyValueChangeKindKey] isEqualToNumber:@(NSKeyValueChangeRemoval)]) {
NSIndexSet *indexSet = [change objectForKey:NSKeyValueChangeIndexesKey];
XLFormSectionDescriptor *removedSection = [[change objectForKey:NSKeyValueChangeOldKey] objectAtIndex:0];
[self.delegate formSectionHasBeenRemoved:removedSection atIndex:indexSet.firstIndex];
}
}
@@ -401,10 +431,16 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
-(void)dealloc
{
@try {
[self removeObserver:self forKeyPath:@"formSections"];
}
@catch (NSException * __unused exception) {}
[self removeObserver:self forKeyPath:XLFormSectionsKey];
[_formSections removeAllObjects];
_formSections = nil;
[_allSections removeAllObjects];
_allSections = nil;
[_allRowsByTag removeAllObjects];
_allRowsByTag = nil;
[_rowObservers removeAllObjects];
_rowObservers = nil;
}
#pragma mark - KVC
@@ -414,19 +450,23 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
return self.formSections.count;
}
- (id)objectInFormSectionsAtIndex:(NSUInteger)index {
- (id)objectInFormSectionsAtIndex:(NSUInteger)index
{
return [self.formSections objectAtIndex:index];
}
- (NSArray *)formSectionsAtIndexes:(NSIndexSet *)indexes {
- (NSArray *)formSectionsAtIndexes:(NSIndexSet *)indexes
{
return [self.formSections objectsAtIndexes:indexes];
}
- (void)insertObject:(XLFormSectionDescriptor *)formSection inFormSectionsAtIndex:(NSUInteger)index {
- (void)insertObject:(XLFormSectionDescriptor *)formSection inFormSectionsAtIndex:(NSUInteger)index
{
[self.formSections insertObject:formSection atIndex:index];
}
- (void)removeObjectFromFormSectionsAtIndex:(NSUInteger)index {
- (void)removeObjectFromFormSectionsAtIndex:(NSUInteger)index
{
[self.formSections removeObjectAtIndex:index];
}
@@ -445,7 +485,8 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
return [self.allSections objectsAtIndexes:indexes];
}
- (void)removeObjectFromAllSectionsAtIndex:(NSUInteger)index {
- (void)removeObjectFromAllSectionsAtIndex:(NSUInteger)index
{
XLFormSectionDescriptor* section = [self.allSections objectAtIndex:index];
[section.allRows enumerateObjectsUsingBlock:^(id obj, NSUInteger __unused idx, BOOL *stop) {
XLFormRowDescriptor * row = (id)obj;
@@ -456,7 +497,8 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
[self.allSections removeObjectAtIndex:index];
}
- (void)insertObject:(XLFormSectionDescriptor *)section inAllSectionsAtIndex:(NSUInteger)index {
- (void)insertObject:(XLFormSectionDescriptor *)section inAllSectionsAtIndex:(NSUInteger)index
{
section.formDescriptor = self;
[self.allSections insertObject:section atIndex:index];
section.hidden = section.hidden;
@@ -466,24 +508,23 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
row.hidden = row.hidden;
row.disabled = row.disabled;
}];
}
#pragma mark - EvaluateForm
-(void)forceEvaluate
{
for (XLFormSectionDescriptor* section in self.allSections){
for (XLFormRowDescriptor* row in section.allRows) {
for (XLFormSectionDescriptor *section in self.allSections) {
for (XLFormRowDescriptor *row in section.allRows) {
[self addRowToTagCollection:row];
}
}
for (XLFormSectionDescriptor* section in self.allSections){
for (XLFormRowDescriptor* row in section.allRows) {
for (XLFormSectionDescriptor *section in self.allSections) {
for (XLFormRowDescriptor *row in section.allRows) {
[row evaluateIsDisabled];
[row evaluateIsHidden];
}
[section evaluateIsHidden];
}
}
@@ -500,60 +541,65 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
-(XLFormRowDescriptor *)nextRowDescriptorForRow:(XLFormRowDescriptor *)row
{
XLFormRowDescriptor *result = nil;
NSUInteger indexOfRow = [row.sectionDescriptor.formRows indexOfObject:row];
if (indexOfRow != NSNotFound){
if (indexOfRow + 1 < row.sectionDescriptor.formRows.count){
return [row.sectionDescriptor.formRows objectAtIndex:++indexOfRow];
if (indexOfRow != NSNotFound) {
if (indexOfRow + 1 < row.sectionDescriptor.formRows.count) {
result = [row.sectionDescriptor.formRows objectAtIndex:++indexOfRow];
}
else{
else {
NSUInteger sectionIndex = [self.formSections indexOfObject:row.sectionDescriptor];
NSUInteger numberOfSections = [self.formSections count];
if (sectionIndex != NSNotFound && sectionIndex < numberOfSections - 1){
if (sectionIndex != NSNotFound && sectionIndex < numberOfSections - 1) {
sectionIndex++;
XLFormSectionDescriptor * sectionDescriptor;
while ([[(sectionDescriptor = [row.sectionDescriptor.formDescriptor.formSections objectAtIndex:sectionIndex]) formRows] count] == 0 && sectionIndex < numberOfSections - 1){
XLFormSectionDescriptor *sectionDescriptor;
while ([[(sectionDescriptor = [row.sectionDescriptor.formDescriptor.formSections objectAtIndex:sectionIndex]) formRows] count] == 0 && sectionIndex < numberOfSections - 1) {
sectionIndex++;
}
return [sectionDescriptor.formRows firstObject];
result = [sectionDescriptor.formRows firstObject];
}
}
}
return nil;
return result;
}
-(XLFormRowDescriptor *)previousRowDescriptorForRow:(XLFormRowDescriptor *)row
{
XLFormRowDescriptor *result = nil;
NSUInteger indexOfRow = [row.sectionDescriptor.formRows indexOfObject:row];
if (indexOfRow != NSNotFound){
if (indexOfRow > 0 ){
return [row.sectionDescriptor.formRows objectAtIndex:--indexOfRow];
if (indexOfRow != NSNotFound) {
if (indexOfRow > 0 ) {
result = [row.sectionDescriptor.formRows objectAtIndex:--indexOfRow];
}
else{
else {
NSUInteger sectionIndex = [self.formSections indexOfObject:row.sectionDescriptor];
if (sectionIndex != NSNotFound && sectionIndex > 0){
if (sectionIndex != NSNotFound && sectionIndex > 0) {
sectionIndex--;
XLFormSectionDescriptor * sectionDescriptor;
while ([[(sectionDescriptor = [row.sectionDescriptor.formDescriptor.formSections objectAtIndex:sectionIndex]) formRows] count] == 0 && sectionIndex > 0 ){
while ([[(sectionDescriptor = [row.sectionDescriptor.formDescriptor.formSections objectAtIndex:sectionIndex]) formRows] count] == 0 && sectionIndex > 0 ) {
sectionIndex--;
}
return [sectionDescriptor.formRows lastObject];
result = [sectionDescriptor.formRows lastObject];
}
}
}
return nil;
return result;
}
-(void)addRowToTagCollection:(XLFormRowDescriptor*) rowDescriptor
-(void)addRowToTagCollection:(XLFormRowDescriptor *)rowDescriptor
{
if (rowDescriptor.tag) {
if (rowDescriptor.tag.length) {
self.allRowsByTag[rowDescriptor.tag] = rowDescriptor;
}
}
-(void)removeRowFromTagCollection:(XLFormRowDescriptor *)rowDescriptor
{
if (rowDescriptor.tag){
if (rowDescriptor.tag.length) {
[self.allRowsByTag removeObjectForKey:rowDescriptor.tag];
}
}
@@ -561,32 +607,36 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
-(void)addObserversOfObject:(id)sectionOrRow predicateType:(XLPredicateType)predicateType
{
NSPredicate* predicate;
NSPredicate *predicate;
id descriptor;
switch(predicateType){
switch (predicateType) {
case XLPredicateTypeHidden:
if ([sectionOrRow isKindOfClass:([XLFormRowDescriptor class])]) {
descriptor = ((XLFormRowDescriptor*)sectionOrRow).tag;
predicate = ((XLFormRowDescriptor*)sectionOrRow).hidden;
descriptor = ((XLFormRowDescriptor *)sectionOrRow).tag;
predicate = ((XLFormRowDescriptor *)sectionOrRow).hidden;
}
else if ([sectionOrRow isKindOfClass:([XLFormSectionDescriptor class])]) {
descriptor = sectionOrRow;
predicate = ((XLFormSectionDescriptor*)sectionOrRow).hidden;
predicate = ((XLFormSectionDescriptor *)sectionOrRow).hidden;
}
break;
case XLPredicateTypeDisabled:
if ([sectionOrRow isKindOfClass:([XLFormRowDescriptor class])]) {
descriptor = ((XLFormRowDescriptor*)sectionOrRow).tag;
predicate = ((XLFormRowDescriptor*)sectionOrRow).disabled;
descriptor = ((XLFormRowDescriptor *)sectionOrRow).tag;
predicate = ((XLFormRowDescriptor *)sectionOrRow).disabled;
}
else {
return;
}
else return;
break;
}
NSMutableArray* tags = [predicate getPredicateVars];
for (NSString* tag in tags) {
NSString* auxTag = [tag formKeyForPredicateType:predicateType];
if (!self.rowObservers[auxTag]){
NSMutableArray *tags = [predicate getPredicateVars];
for (NSString *tag in tags) {
NSString *auxTag = [tag formKeyForPredicateType:predicateType];
if (!self.rowObservers[auxTag]) {
self.rowObservers[auxTag] = [NSMutableArray array];
}
if (![self.rowObservers[auxTag] containsObject:descriptor])
@@ -597,31 +647,32 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
-(void)removeObserversOfObject:(id)sectionOrRow predicateType:(XLPredicateType)predicateType
{
NSPredicate* predicate;
NSPredicate *predicate;
id descriptor;
switch(predicateType){
switch(predicateType) {
case XLPredicateTypeHidden:
if ([sectionOrRow isKindOfClass:([XLFormRowDescriptor class])]) {
descriptor = ((XLFormRowDescriptor*)sectionOrRow).tag;
predicate = ((XLFormRowDescriptor*)sectionOrRow).hidden;
descriptor = ((XLFormRowDescriptor *)sectionOrRow).tag;
predicate = ((XLFormRowDescriptor *)sectionOrRow).hidden;
}
else if ([sectionOrRow isKindOfClass:([XLFormSectionDescriptor class])]) {
descriptor = sectionOrRow;
predicate = ((XLFormSectionDescriptor*)sectionOrRow).hidden;
predicate = ((XLFormSectionDescriptor *)sectionOrRow).hidden;
}
break;
case XLPredicateTypeDisabled:
if ([sectionOrRow isKindOfClass:([XLFormRowDescriptor class])]) {
descriptor = ((XLFormRowDescriptor*)sectionOrRow).tag;
predicate = ((XLFormRowDescriptor*)sectionOrRow).disabled;
descriptor = ((XLFormRowDescriptor *)sectionOrRow).tag;
predicate = ((XLFormRowDescriptor *)sectionOrRow).disabled;
}
break;
}
if (descriptor && [predicate isKindOfClass:[NSPredicate class] ]) {
NSMutableArray* tags = [predicate getPredicateVars];
for (NSString* tag in tags) {
NSString* auxTag = [tag formKeyForPredicateType:predicateType];
if (self.rowObservers[auxTag]){
if (descriptor && [predicate isKindOfClass:[NSPredicate class]]) {
NSMutableArray *tags = [predicate getPredicateVars];
for (NSString *tag in tags) {
NSString *auxTag = [tag formKeyForPredicateType:predicateType];
if (self.rowObservers[auxTag]) {
[self.rowObservers[auxTag] removeObject:descriptor];
}
}
+41 -39
View File
@@ -43,22 +43,22 @@ typedef NS_ENUM(NSUInteger, XLFormPresentationMode) {
XLFormPresentationModePresent
};
typedef void(^XLOnChangeBlock)(id __nullable oldValue,id __nullable newValue,XLFormRowDescriptor* __nonnull rowDescriptor);
typedef void(^XLOnChangeBlock)(id __nullable oldValue, id __nullable newValue, XLFormRowDescriptor * __nonnull rowDescriptor);
@interface XLFormRowDescriptor : NSObject
@property (nullable) id cellClass;
@property (readwrite, nullable) NSString * tag;
@property (readonly, nonnull) NSString * rowType;
@property (nullable) NSString * title;
@property (nonatomic, nullable) id value;
@property (nullable) Class valueTransformer;
@property UITableViewCellStyle cellStyle;
@property (nonatomic) CGFloat height;
@property (nonatomic, nullable, strong) id cellClass;
@property (nonatomic, nullable, copy , readwrite) NSString * tag;
@property (nonatomic, nonnull , copy , readonly) NSString * rowType;
@property (nonatomic, nullable, copy ) NSString * title;
@property (nonatomic, nullable, strong) id value;
@property (nonatomic, nullable, strong) Class valueTransformer;
@property (nonatomic, assign ) UITableViewCellStyle cellStyle;
@property (nonatomic, assign ) CGFloat height;
@property (copy, nullable) XLOnChangeBlock onChangeBlock;
@property BOOL useValueFormatterDuringInput;
@property (nullable) NSFormatter *valueFormatter;
@property (nonatomic, copy , nullable) XLOnChangeBlock onChangeBlock;
@property (nonatomic, assign) BOOL useValueFormatterDuringInput;
@property (nonatomic, strong, nullable) NSFormatter *valueFormatter;
// returns the display text for the row descriptor, taking into account NSFormatters and default placeholder values
- (nonnull NSString *) displayTextValue;
@@ -66,20 +66,22 @@ typedef void(^XLOnChangeBlock)(id __nullable oldValue,id __nullable newValue,XLF
// returns the editing text value for the row descriptor, taking into account NSFormatters.
- (nonnull NSString *) editTextValue;
@property (nonatomic, readonly, nonnull) NSMutableDictionary * cellConfig;
@property (nonatomic, readonly, nonnull) NSMutableDictionary * cellConfigForSelector;
@property (nonatomic, readonly, nonnull) NSMutableDictionary * cellConfigIfDisabled;
@property (nonatomic, readonly, nonnull) NSMutableDictionary * cellConfigAtConfigure;
@property (nonatomic, readonly, nonnull, strong) NSMutableDictionary * cellConfig;
@property (nonatomic, readonly, nonnull, strong) NSMutableDictionary * cellConfigForSelector;
@property (nonatomic, readonly, nonnull, strong) NSMutableDictionary * cellConfigIfDisabled;
@property (nonatomic, readonly, nonnull, strong) NSMutableDictionary * cellConfigAtConfigure;
@property (nonnull) id disabled;
@property (nonatomic, nonnull, strong) id disabled;
-(BOOL)isDisabled;
@property (nonnull) id hidden;
@property (nonatomic, nonnull, strong) id hidden;
-(BOOL)isHidden;
@property (getter=isRequired) BOOL required;
@property (nonnull) XLFormAction * action;
@property (getter=isRequired, nonatomic, assign) BOOL required;
@property (weak, null_unspecified) XLFormSectionDescriptor * sectionDescriptor;
@property (nonatomic, nonnull, strong) XLFormAction * action;
@property (nonatomic, weak, null_unspecified) XLFormSectionDescriptor * sectionDescriptor;
+(nonnull instancetype)formRowDescriptorWithTag:(nullable NSString *)tag rowType:(nonnull NSString *)rowType;
+(nonnull instancetype)formRowDescriptorWithTag:(nullable NSString *)tag rowType:(nonnull NSString *)rowType title:(nullable NSString *)title;
@@ -87,7 +89,7 @@ typedef void(^XLOnChangeBlock)(id __nullable oldValue,id __nullable newValue,XLF
-(nonnull XLFormBaseCell *)cellForFormController:(nonnull XLFormViewController *)formController;
@property (nullable) NSString *requireMsg;
@property (nonatomic, nullable, copy) NSString *requireMsg;
-(void)addValidator:(nonnull id<XLFormValidatorProtocol>)validator;
-(void)removeValidator:(nonnull id<XLFormValidatorProtocol>)validator;
-(nullable XLFormValidationStatus *)doValidation;
@@ -95,9 +97,9 @@ typedef void(^XLOnChangeBlock)(id __nullable oldValue,id __nullable newValue,XLF
// ===========================
// property used for Selectors
// ===========================
@property (nullable) NSString * noValueDisplayText;
@property (nullable) NSString * selectorTitle;
@property (nullable) NSArray * selectorOptions;
@property (nonatomic, nullable, copy) NSString * noValueDisplayText;
@property (nonatomic, nullable, copy) NSString * selectorTitle;
@property (nonatomic, nullable, strong) NSArray * selectorOptions;
@property (null_unspecified) id leftRightSelectorLeftOptionSelected;
@@ -126,13 +128,13 @@ typedef NS_ENUM(NSUInteger, XLFormLeftRightSelectorOptionLeftValueChangePolicy)
@interface XLFormLeftRightSelectorOption : NSObject
@property (nonatomic, assign) XLFormLeftRightSelectorOptionLeftValueChangePolicy leftValueChangePolicy;
@property (readonly, nonnull) id leftValue;
@property (readonly, nonnull) NSArray * rightOptions;
@property (readonly, null_unspecified) NSString * httpParameterKey;
@property (nullable) Class rightSelectorControllerClass;
@property (nonatomic, readonly, nonnull) id leftValue;
@property (nonatomic, readonly, nonnull) NSArray * rightOptions;
@property (nonatomic, readonly, null_unspecified, copy) NSString * httpParameterKey;
@property (nonatomic, nullable) Class rightSelectorControllerClass;
@property (nullable) NSString * noValueDisplayText;
@property (nullable) NSString * selectorTitle;
@property (nonatomic, nullable, copy) NSString * noValueDisplayText;
@property (nonatomic, nullable, copy) NSString * selectorTitle;
+(nonnull XLFormLeftRightSelectorOption *)formLeftRightSelectorOptionWithLeftValue:(nonnull id)leftValue
@@ -154,16 +156,16 @@ typedef NS_ENUM(NSUInteger, XLFormLeftRightSelectorOptionLeftValueChangePolicy)
@interface XLFormAction : NSObject
@property (nullable, nonatomic, strong) Class viewControllerClass;
@property (nullable, nonatomic, strong) NSString * viewControllerStoryboardId;
@property (nullable, nonatomic, strong) NSString * viewControllerNibName;
@property (nullable, nonatomic) Class viewControllerClass;
@property (nullable, nonatomic, copy) NSString * viewControllerStoryboardId;
@property (nullable, nonatomic, copy) NSString * viewControllerNibName;
@property (nonatomic) XLFormPresentationMode viewControllerPresentationMode;
@property (nonatomic, assign) XLFormPresentationMode viewControllerPresentationMode;
@property (nullable, nonatomic, strong) void (^formBlock)(XLFormRowDescriptor * __nonnull sender);
@property (nullable, nonatomic, copy) void (^formBlock)(XLFormRowDescriptor * __nonnull sender);
@property (nullable, nonatomic) SEL formSelector;
@property (nullable, nonatomic, strong) NSString * formSegueIdenfifier DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("Use formSegueIdentifier instead");
@property (nullable, nonatomic, strong) NSString * formSegueIdentifier;
@property (nullable, nonatomic, strong) Class formSegueClass;
@property (nullable, nonatomic, copy) NSString * formSegueIdenfifier DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("Use formSegueIdentifier instead");
@property (nullable, nonatomic, copy) NSString * formSegueIdentifier;
@property (nullable, nonatomic) Class formSegueClass;
@end
+173 -120
View File
@@ -33,7 +33,7 @@ CGFloat XLFormRowInitialHeight = -2;
@interface XLFormDescriptor (_XLFormRowDescriptor)
@property (readonly) NSDictionary* allRowsByTag;
@property (nonatomic, readonly, strong) NSDictionary *allRowsByTag;
-(void)addObserversOfObject:(id)sectionOrRow predicateType:(XLPredicateType)predicateType;
-(void)removeObserversOfObject:(id)sectionOrRow predicateType:(XLPredicateType)predicateType;
@@ -42,22 +42,26 @@ CGFloat XLFormRowInitialHeight = -2;
@interface XLFormSectionDescriptor (_XLFormRowDescriptor)
-(void)showFormRow:(XLFormRowDescriptor*)formRow;
-(void)hideFormRow:(XLFormRowDescriptor*)formRow;
-(void)showFormRow:(XLFormRowDescriptor *)formRow;
-(void)hideFormRow:(XLFormRowDescriptor *)formRow;
@end
#import "NSObject+XLFormAdditions.h"
NSString * const XLValueKey = @"value";
NSString * const XLDisablePredicateCacheKey = @"disablePredicateCache";
NSString * const XLHidePredicateCacheKey = @"hidePredicateCache";
@interface XLFormRowDescriptor() <NSCopying>
@property XLFormBaseCell * cell;
@property (nonatomic) NSMutableArray *validators;
@property (nonatomic, strong) XLFormBaseCell *cell;
@property (nonatomic, strong) NSMutableArray *validators;
@property BOOL isDirtyDisablePredicateCache;
@property (nonatomic) NSNumber* disablePredicateCache;
@property BOOL isDirtyHidePredicateCache;
@property (nonatomic) NSNumber* hidePredicateCache;
@property (nonatomic, assign) BOOL isDirtyDisablePredicateCache;
@property (nonatomic, copy ) NSNumber *disablePredicateCache;
@property (nonatomic, assign) BOOL isDirtyHidePredicateCache;
@property (nonatomic, copy ) NSNumber *hidePredicateCache;
@end
@@ -81,8 +85,7 @@ CGFloat XLFormRowInitialHeight = -2;
-(instancetype)initWithTag:(NSString *)tag rowType:(NSString *)rowType title:(NSString *)title;
{
self = [super init];
if (self){
if (self = [super init]) {
NSAssert(((![rowType isEqualToString:XLFormRowDescriptorTypeSelectorPopover] && ![rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelectorPopover]) || (([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) && ([rowType isEqualToString:XLFormRowDescriptorTypeSelectorPopover] || [rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelectorPopover]))), @"You must be running under UIUserInterfaceIdiomPad to use either XLFormRowDescriptorTypeSelectorPopover or XLFormRowDescriptorTypeMultipleSelectorPopover rows.");
_tag = tag;
_disabled = @NO;
@@ -99,11 +102,19 @@ CGFloat XLFormRowInitialHeight = -2;
_isDirtyHidePredicateCache = YES;
_hidePredicateCache = nil;
_height = XLFormRowInitialHeight;
[self addObserver:self forKeyPath:@"value" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
[self addObserver:self forKeyPath:@"disablePredicateCache" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
[self addObserver:self forKeyPath:@"hidePredicateCache" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
[self addObserver:self
forKeyPath:XLValueKey
options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
[self addObserver:self
forKeyPath:XLDisablePredicateCacheKey
options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
[self addObserver:self
forKeyPath:XLHidePredicateCacheKey
options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
}
return self;
}
@@ -119,13 +130,16 @@ CGFloat XLFormRowInitialHeight = -2;
-(XLFormBaseCell *)cellForFormController:(XLFormViewController * __unused)formController
{
if (!_cell){
if (!_cell) {
id cellClass = self.cellClass ?: [XLFormViewController cellClassesForRowDescriptorTypes][self.rowType];
NSBundle *bundle = [NSBundle mainBundle];
NSString *cellClassString = cellClass;
NSString *cellResource = nil;
NSAssert(cellClass, @"Not defined XLFormRowDescriptorType: %@", self.rowType ?: @"");
if ([cellClass isKindOfClass:[NSString class]]) {
NSString *cellClassString = cellClass;
NSString *cellResource = nil;
NSBundle *bundle = nil;
if ([cellClassString rangeOfString:@"/"].location != NSNotFound) {
NSArray *components = [cellClassString componentsSeparatedByString:@"/"];
cellResource = [components lastObject];
@@ -133,94 +147,109 @@ CGFloat XLFormRowInitialHeight = -2;
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:folderName];
bundle = [NSBundle bundleWithPath:bundlePath];
} else {
bundle = [NSBundle bundleForClass:NSClassFromString(cellClass)];
cellResource = cellClassString;
}
NSParameterAssert(bundle != nil);
NSParameterAssert(cellResource != nil);
if ([bundle pathForResource:cellResource ofType:@"nib"]){
_cell = [[bundle loadNibNamed:cellResource owner:nil options:nil] firstObject];
cellResource = [cellClassString componentsSeparatedByString:@"."].lastObject;
}
} else {
cellResource = [NSStringFromClass(cellClass) componentsSeparatedByString:@"."].lastObject;
}
if ([bundle pathForResource:cellResource ofType:@"nib"]) {
_cell = [[bundle loadNibNamed:cellResource owner:nil options:nil] firstObject];
} else {
_cell = [[cellClass alloc] initWithStyle:self.cellStyle reuseIdentifier:nil];
}
_cell.rowDescriptor = self;
NSAssert([_cell isKindOfClass:[XLFormBaseCell class]], @"UITableViewCell must extend from XLFormBaseCell");
[self configureCellAtCreationTime];
}
return _cell;
}
- (void)configureCellAtCreationTime
{
[self.cellConfigAtConfigure enumerateKeysAndObjectsUsingBlock:^(NSString *keyPath, id value, __unused BOOL *stop) {
[_cell setValue:(value == [NSNull null]) ? nil : value forKeyPath:keyPath];
[self.cell setValue:(value == [NSNull null]) ? nil : value forKeyPath:keyPath];
}];
}
-(NSMutableDictionary *)cellConfig
{
if (_cellConfig) return _cellConfig;
_cellConfig = [NSMutableDictionary dictionary];
if (!_cellConfig) {
_cellConfig = [NSMutableDictionary dictionary];
}
return _cellConfig;
}
-(NSMutableDictionary *)cellConfigForSelector
{
if (_cellConfigForSelector) return _cellConfigForSelector;
_cellConfigForSelector = [NSMutableDictionary dictionary];
if (!_cellConfigForSelector) {
_cellConfigForSelector = [NSMutableDictionary dictionary];
}
return _cellConfigForSelector;
}
-(NSMutableDictionary *)cellConfigIfDisabled
{
if (_cellConfigIfDisabled) return _cellConfigIfDisabled;
_cellConfigIfDisabled = [NSMutableDictionary dictionary];
if (!_cellConfigIfDisabled) {
_cellConfigIfDisabled = [NSMutableDictionary dictionary];
}
return _cellConfigIfDisabled;
}
-(NSMutableDictionary *)cellConfigAtConfigure
{
if (_cellConfigAtConfigure) return _cellConfigAtConfigure;
_cellConfigAtConfigure = [NSMutableDictionary dictionary];
if (!_cellConfigAtConfigure) {
_cellConfigAtConfigure = [NSMutableDictionary dictionary];
}
return _cellConfigAtConfigure;
}
-(NSString*)editTextValue
-(NSString *)editTextValue
{
NSString *result = @"";
if (self.value) {
if (self.valueFormatter) {
if (self.useValueFormatterDuringInput) {
return [self displayTextValue];
}else{
// have formatter, but we don't want to use it during editing
return [self.value displayText];
result = [self displayTextValue];
}
else {
// have formatter, but we don't want to use it during editing
result = [self.value displayText];
}
}else{
// have value, but no formatter, use the value's displayText
return [self.value displayText];
}
}else{
// placeholder
return @"";
else {
// have value, but no formatter, use the value's displayText
result = [self.value displayText];
}
}
return result;
}
-(NSString*)displayTextValue
-(NSString *)displayTextValue
{
NSString *result = self.noValueDisplayText;
if (self.value) {
if (self.valueFormatter) {
return [self.valueFormatter stringForObjectValue:self.value];
result = [self.valueFormatter stringForObjectValue:self.value];
}
else{
return [self.value displayText];
else {
result = [self.value displayText];
}
}
else {
return self.noValueDisplayText;
}
return result;
}
-(NSString *)description
@@ -230,9 +259,10 @@ CGFloat XLFormRowInitialHeight = -2;
-(XLFormAction *)action
{
if (!_action){
if (!_action) {
_action = [[XLFormAction alloc] init];
}
return _action;
}
@@ -243,13 +273,15 @@ CGFloat XLFormRowInitialHeight = -2;
-(CGFloat)height
{
if (_height == XLFormRowInitialHeight){
if (_height == XLFormRowInitialHeight) {
if ([[self.cell class] respondsToSelector:@selector(formDescriptorCellHeightForRowDescriptor:)]){
return [[self.cell class] formDescriptorCellHeightForRowDescriptor:self];
} else {
}
else {
_height = XLFormUnspecifiedCellHeight;
}
}
return _height;
}
@@ -260,71 +292,76 @@ CGFloat XLFormRowInitialHeight = -2;
// In the implementation
-(id)copyWithZone:(NSZone *)zone
{
XLFormRowDescriptor * rowDescriptorCopy = [XLFormRowDescriptor formRowDescriptorWithTag:nil rowType:[self.rowType copy] title:[self.title copy]];
XLFormRowDescriptor *rowDescriptorCopy = [XLFormRowDescriptor formRowDescriptorWithTag:nil
rowType:[self.rowType copy]
title:[self.title copy]];
rowDescriptorCopy.cellClass = [self.cellClass copy];
[rowDescriptorCopy.cellConfig addEntriesFromDictionary:self.cellConfig];
[rowDescriptorCopy.cellConfigAtConfigure addEntriesFromDictionary:self.cellConfigAtConfigure];
rowDescriptorCopy.valueTransformer = [self.valueTransformer copy];
rowDescriptorCopy->_hidden = _hidden;
rowDescriptorCopy->_disabled = _disabled;
rowDescriptorCopy.hidden = self.hidden;
rowDescriptorCopy.disabled = self.disabled;
rowDescriptorCopy.required = self.isRequired;
rowDescriptorCopy.isDirtyDisablePredicateCache = YES;
rowDescriptorCopy.isDirtyHidePredicateCache = YES;
rowDescriptorCopy.validators = [self.validators mutableCopy];
// =====================
// properties for Button
// =====================
rowDescriptorCopy.action = [self.action copy];
// ===========================
// property used for Selectors
// ===========================
rowDescriptorCopy.noValueDisplayText = [self.noValueDisplayText copy];
rowDescriptorCopy.selectorTitle = [self.selectorTitle copy];
rowDescriptorCopy.selectorOptions = [self.selectorOptions copy];
rowDescriptorCopy.leftRightSelectorLeftOptionSelected = [self.leftRightSelectorLeftOptionSelected copy];
return rowDescriptorCopy;
}
-(void)dealloc
{
[self removeObserver:self forKeyPath:XLValueKey];
[self removeObserver:self forKeyPath:XLDisablePredicateCacheKey];
[self removeObserver:self forKeyPath:XLHidePredicateCacheKey];
[self.sectionDescriptor.formDescriptor removeObserversOfObject:self predicateType:XLPredicateTypeDisabled];
[self.sectionDescriptor.formDescriptor removeObserversOfObject:self predicateType:XLPredicateTypeHidden];
@try {
[self removeObserver:self forKeyPath:@"value"];
}
@catch (NSException * __unused exception) {}
@try {
[self removeObserver:self forKeyPath:@"disablePredicateCache"];
}
@catch (NSException * __unused exception) {}
@try {
[self removeObserver:self forKeyPath:@"hidePredicateCache"];
}
@catch (NSException * __unused exception) {}
_cell = nil;
[self.validators removeAllObjects];
self.validators = nil;
}
#pragma mark - KVO
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (!self.sectionDescriptor) return;
if (object == self && ([keyPath isEqualToString:@"value"] || [keyPath isEqualToString:@"hidePredicateCache"] || [keyPath isEqualToString:@"disablePredicateCache"])){
if (!self.sectionDescriptor) {
return;
}
else if (object == self && ([keyPath isEqualToString:XLValueKey] ||
[keyPath isEqualToString:XLHidePredicateCacheKey] || [keyPath isEqualToString:XLDisablePredicateCacheKey])) {
if ([[change objectForKey:NSKeyValueChangeKindKey] isEqualToNumber:@(NSKeyValueChangeSetting)]){
id newValue = [change objectForKey:NSKeyValueChangeNewKey];
id oldValue = [change objectForKey:NSKeyValueChangeOldKey];
if ([keyPath isEqualToString:@"value"]){
if ([keyPath isEqualToString:XLValueKey]) {
[self.sectionDescriptor.formDescriptor.delegate formRowDescriptorValueHasChanged:object oldValue:oldValue newValue:newValue];
if (self.onChangeBlock) {
self.onChangeBlock(oldValue, newValue, self);
}
}
else{
[self.sectionDescriptor.formDescriptor.delegate formRowDescriptorPredicateHasChanged:object oldValue:oldValue newValue:newValue predicateType:([keyPath isEqualToString:@"hidePredicateCache"] ? XLPredicateTypeHidden : XLPredicateTypeDisabled)];
else {
[self.sectionDescriptor.formDescriptor.delegate formRowDescriptorPredicateHasChanged:object
oldValue:oldValue
newValue:newValue
predicateType:([keyPath isEqualToString:XLHidePredicateCacheKey] ? XLPredicateTypeHidden : XLPredicateTypeDisabled)];
}
}
}
@@ -334,12 +371,14 @@ CGFloat XLFormRowInitialHeight = -2;
-(BOOL)isDisabled
{
if (self.sectionDescriptor.formDescriptor.isDisabled){
if (self.sectionDescriptor.formDescriptor.isDisabled) {
return YES;
}
if (self.isDirtyDisablePredicateCache) {
[self evaluateIsDisabled];
}
return [self.disablePredicateCache boolValue];
}
@@ -348,11 +387,12 @@ CGFloat XLFormRowInitialHeight = -2;
if ([_disabled isKindOfClass:[NSPredicate class]]){
[self.sectionDescriptor.formDescriptor removeObserversOfObject:self predicateType:XLPredicateTypeDisabled];
}
_disabled = [disabled isKindOfClass:[NSString class]] ? [disabled formPredicate] : disabled;
if ([_disabled isKindOfClass:[NSPredicate class]]){
[self.sectionDescriptor.formDescriptor addObserversOfObject:self predicateType:XLPredicateTypeDisabled];
}
[self evaluateIsDisabled];
}
@@ -361,7 +401,8 @@ CGFloat XLFormRowInitialHeight = -2;
if ([_disabled isKindOfClass:[NSPredicate class]]) {
if (!self.sectionDescriptor.formDescriptor) {
self.isDirtyDisablePredicateCache = YES;
} else {
}
else {
@try {
self.disablePredicateCache = @([_disabled evaluateWithObject:self substitutionVariables:self.sectionDescriptor.formDescriptor.allRowsByTag ?: @{}]);
}
@@ -371,12 +412,14 @@ CGFloat XLFormRowInitialHeight = -2;
};
}
}
else{
else {
self.disablePredicateCache = _disabled;
}
if ([self.disablePredicateCache boolValue]){
if ([self.disablePredicateCache boolValue]) {
[self.cell resignFirstResponder];
}
return [self.disablePredicateCache boolValue];
}
@@ -387,9 +430,9 @@ CGFloat XLFormRowInitialHeight = -2;
-(void)setDisablePredicateCache:(NSNumber*)disablePredicateCache
{
NSParameterAssert(disablePredicateCache);
NSParameterAssert(disablePredicateCache != nil);
self.isDirtyDisablePredicateCache = NO;
if (!_disablePredicateCache || ![_disablePredicateCache isEqualToNumber:disablePredicateCache]){
if (_disablePredicateCache == nil || ![_disablePredicateCache isEqualToNumber:disablePredicateCache]){
_disablePredicateCache = disablePredicateCache;
}
}
@@ -408,9 +451,9 @@ CGFloat XLFormRowInitialHeight = -2;
-(void)setHidePredicateCache:(NSNumber *)hidePredicateCache
{
NSParameterAssert(hidePredicateCache);
NSParameterAssert(hidePredicateCache != nil);
self.isDirtyHidePredicateCache = NO;
if (!_hidePredicateCache || ![_hidePredicateCache isEqualToNumber:hidePredicateCache]){
if (_hidePredicateCache == nil || ![_hidePredicateCache isEqualToNumber:hidePredicateCache]){
_hidePredicateCache = hidePredicateCache;
}
}
@@ -420,6 +463,7 @@ CGFloat XLFormRowInitialHeight = -2;
if (self.isDirtyHidePredicateCache) {
return [self evaluateIsHidden];
}
return [self.hidePredicateCache boolValue];
}
@@ -428,7 +472,8 @@ CGFloat XLFormRowInitialHeight = -2;
if ([_hidden isKindOfClass:[NSPredicate class]]) {
if (!self.sectionDescriptor.formDescriptor) {
self.isDirtyHidePredicateCache = YES;
} else {
}
else {
@try {
self.hidePredicateCache = @([_hidden evaluateWithObject:self substitutionVariables:self.sectionDescriptor.formDescriptor.allRowsByTag ?: @{}]);
}
@@ -438,16 +483,18 @@ CGFloat XLFormRowInitialHeight = -2;
};
}
}
else{
else {
self.hidePredicateCache = _hidden;
}
if ([self.hidePredicateCache boolValue]){
[self.cell resignFirstResponder];
[self.sectionDescriptor hideFormRow:self];
}
else{
else {
[self.sectionDescriptor showFormRow:self];
}
return [self.hidePredicateCache boolValue];
}
@@ -457,10 +504,12 @@ CGFloat XLFormRowInitialHeight = -2;
if ([_hidden isKindOfClass:[NSPredicate class]]){
[self.sectionDescriptor.formDescriptor removeObserversOfObject:self predicateType:XLPredicateTypeHidden];
}
_hidden = [hidden isKindOfClass:[NSString class]] ? [hidden formPredicate] : hidden;
if ([_hidden isKindOfClass:[NSPredicate class]]){
[self.sectionDescriptor.formDescriptor addObserversOfObject:self predicateType:XLPredicateTypeHidden];
}
[self evaluateIsHidden]; // check and update if this row should be hidden.
}
@@ -474,34 +523,35 @@ CGFloat XLFormRowInitialHeight = -2;
-(void)addValidator:(id<XLFormValidatorProtocol>)validator
{
if (validator == nil || ![validator conformsToProtocol:@protocol(XLFormValidatorProtocol)])
if (validator == nil || ![validator conformsToProtocol:@protocol(XLFormValidatorProtocol)]) {
return;
if(![self.validators containsObject:validator]) {
}
else if (![self.validators containsObject:validator]) {
[self.validators addObject:validator];
}
}
-(void)removeValidator:(id<XLFormValidatorProtocol>)validator
{
if (validator == nil|| ![validator conformsToProtocol:@protocol(XLFormValidatorProtocol)])
if (validator == nil || ![validator conformsToProtocol:@protocol(XLFormValidatorProtocol)]) {
return;
if ([self.validators containsObject:validator]) {
}
else if ([self.validators containsObject:validator]) {
[self.validators removeObject:validator];
}
}
- (BOOL)valueIsEmpty
{
return self.value == nil || [self.value isKindOfClass:[NSNull class]] || ([self.value respondsToSelector:@selector(length)] && [self.value length]==0) ||
([self.value respondsToSelector:@selector(count)] && [self.value count]==0);
return self.value == nil || [self.value isKindOfClass:[NSNull class]] ||
([self.value respondsToSelector:@selector(length)] && [self.value length] == 0) ||
([self.value respondsToSelector:@selector(count)] && [self.value count] == 0);
}
-(XLFormValidationStatus *)doValidation
{
XLFormValidationStatus *valStatus = nil;
if (self.required) {
// do required validation here
if ([self valueIsEmpty]) {
@@ -509,22 +559,24 @@ CGFloat XLFormRowInitialHeight = -2;
NSString *msg = nil;
if (self.requireMsg != nil) {
msg = self.requireMsg;
} else {
}
else {
// default message for required msg
msg = NSLocalizedString(@"%@ can't be empty", nil);
}
if (self.title != nil) {
if (self.title.length) {
valStatus.msg = [NSString stringWithFormat:msg, self.title];
} else {
}
else {
valStatus.msg = [NSString stringWithFormat:msg, self.tag];
}
return valStatus;
}
}
// custom validator
for(id<XLFormValidatorProtocol> v in self.validators) {
for (id<XLFormValidatorProtocol> v in self.validators) {
if ([v conformsToProtocol:@protocol(XLFormValidatorProtocol)]) {
XLFormValidationStatus *vStatus = [v isValid:self];
// fail validation
@@ -532,10 +584,12 @@ CGFloat XLFormRowInitialHeight = -2;
return vStatus;
}
valStatus = vStatus;
} else {
}
else {
valStatus = nil;
}
}
return valStatus;
}
@@ -591,13 +645,13 @@ CGFloat XLFormRowInitialHeight = -2;
-(instancetype)initWithLeftValue:(NSString *)leftValue httpParameterKey:(NSString *)httpParameterKey rightOptions:(NSArray *)rightOptions
{
self = [super init];
if (self){
if (self = [super init]) {
_selectorTitle = nil;
_leftValue = leftValue;
_rightOptions = rightOptions;
_httpParameterKey = httpParameterKey;
}
return self;
}
@@ -608,10 +662,10 @@ CGFloat XLFormRowInitialHeight = -2;
- (instancetype)init
{
self = [super init];
if (self) {
if (self = [super init]) {
_viewControllerPresentationMode = XLFormPresentationModeDefault;
}
return self;
}
@@ -623,24 +677,25 @@ CGFloat XLFormRowInitialHeight = -2;
if (self.viewControllerClass){
actionCopy.viewControllerClass = [self.viewControllerClass copy];
}
else if ([self.viewControllerStoryboardId length] != 0){
else if ([self.viewControllerStoryboardId length] != 0) {
actionCopy.viewControllerStoryboardId = [self.viewControllerStoryboardId copy];
}
else if ([self.viewControllerNibName length] != 0){
else if ([self.viewControllerNibName length] != 0) {
actionCopy.viewControllerNibName = [self.viewControllerNibName copy];
}
if (self.formBlock){
if (self.formBlock) {
actionCopy.formBlock = [self.formBlock copy];
}
else if (self.formSelector){
else if (self.formSelector) {
actionCopy.formSelector = self.formSelector;
}
else if (self.formSegueIdentifier){
else if (self.formSegueIdentifier) {
actionCopy.formSegueIdentifier = [self.formSegueIdentifier copy];
}
else if (self.formSegueClass){
actionCopy.formSegueClass = [self.formSegueClass copy];
}
return actionCopy;
}
@@ -665,7 +720,6 @@ CGFloat XLFormRowInitialHeight = -2;
_viewControllerStoryboardId = viewControllerStoryboardId;
}
-(void)setFormSelector:(SEL)formSelector
{
_formBlock = nil;
@@ -674,7 +728,6 @@ CGFloat XLFormRowInitialHeight = -2;
_formSelector = formSelector;
}
-(void)setFormBlock:(void (^)(XLFormRowDescriptor *))formBlock
{
_formSegueClass = nil;
+10 -10
View File
@@ -42,19 +42,19 @@ typedef NS_ENUM(NSUInteger, XLFormSectionInsertMode) {
@interface XLFormSectionDescriptor : NSObject
@property (nonatomic, nullable) NSString * title;
@property (nonatomic, nullable) NSString * footerTitle;
@property (readonly, nonnull) NSMutableArray * formRows;
@property (nonatomic, nullable, copy) NSString * title;
@property (nonatomic, nullable, copy) NSString * footerTitle;
@property (nonatomic, readonly, nonnull, strong) NSMutableArray * formRows;
@property (readonly) XLFormSectionInsertMode sectionInsertMode;
@property (readonly) XLFormSectionOptions sectionOptions;
@property (nullable) XLFormRowDescriptor * multivaluedRowTemplate;
@property (readonly, nullable) XLFormRowDescriptor * multivaluedAddButton;
@property (nonatomic, nullable) NSString * multivaluedTag;
@property (nonatomic, readonly, assign) XLFormSectionInsertMode sectionInsertMode;
@property (nonatomic, readonly, assign) XLFormSectionOptions sectionOptions;
@property (nonatomic, nullable, strong) XLFormRowDescriptor * multivaluedRowTemplate;
@property (nonatomic, readonly, nullable, strong) XLFormRowDescriptor * multivaluedAddButton;
@property (nonatomic, nullable, copy) NSString * multivaluedTag;
@property (weak, null_unspecified) XLFormDescriptor * formDescriptor;
@property (nonatomic, weak, null_unspecified) XLFormDescriptor * formDescriptor;
@property (nonnull) id hidden;
@property (nonatomic, nonnull, strong) id hidden;
-(BOOL)isHidden;
+(nonnull instancetype)formSection;
+88 -64
View File
@@ -29,15 +29,16 @@
#import "NSString+XLFormAdditions.h"
#import "UIView+XLFormAdditions.h"
NSString * const XLFormRowsKey = @"formRows";
@interface XLFormDescriptor (_XLFormSectionDescriptor)
@property (readonly) NSDictionary* allRowsByTag;
@property (nonatomic, weak, readonly) NSDictionary *allRowsByTag;
-(void)addRowToTagCollection:(XLFormRowDescriptor*)rowDescriptor;
-(void)removeRowFromTagCollection:(XLFormRowDescriptor*) rowDescriptor;
-(void)showFormSection:(XLFormSectionDescriptor*)formSection;
-(void)hideFormSection:(XLFormSectionDescriptor*)formSection;
-(void)addRowToTagCollection:(XLFormRowDescriptor *)rowDescriptor;
-(void)removeRowFromTagCollection:(XLFormRowDescriptor *) rowDescriptor;
-(void)showFormSection:(XLFormSectionDescriptor *)formSection;
-(void)hideFormSection:(XLFormSectionDescriptor *)formSection;
-(void)addObserversOfObject:(id)sectionOrRow predicateType:(XLPredicateType)predicateType;
-(void)removeObserversOfObject:(id)sectionOrRow predicateType:(XLPredicateType)predicateType;
@@ -46,10 +47,11 @@
@interface XLFormSectionDescriptor()
@property NSMutableArray * formRows;
@property NSMutableArray * allRows;
@property BOOL isDirtyHidePredicateCache;
@property (nonatomic) NSNumber* hidePredicateCache;
@property (nonatomic, strong) NSMutableArray *formRows;
@property (nonatomic, strong) NSMutableArray *allRows;
@property (nonatomic, assign) BOOL isDirtyHidePredicateCache;
@property (nonatomic, copy ) NSNumber *hidePredicateCache;
@end
@@ -60,8 +62,7 @@
-(instancetype)init
{
self = [super init];
if (self){
if (self = [super init]) {
_formRows = [NSMutableArray array];
_allRows = [NSMutableArray array];
_sectionInsertMode = XLFormSectionInsertModeLastRow;
@@ -71,25 +72,35 @@
_hidden = @NO;
_hidePredicateCache = @NO;
_isDirtyHidePredicateCache = YES;
[self addObserver:self forKeyPath:@"formRows" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:0];
[self addObserver:self
forKeyPath:XLFormRowsKey
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:0];
}
return self;
}
-(instancetype)initWithTitle:(NSString *)title sectionOptions:(XLFormSectionOptions)sectionOptions sectionInsertMode:(XLFormSectionInsertMode)sectionInsertMode{
self = [self init];
if (self){
-(instancetype)initWithTitle:(NSString *)title sectionOptions:(XLFormSectionOptions)sectionOptions sectionInsertMode:(XLFormSectionInsertMode)sectionInsertMode
{
if (self = [self init]) {
_sectionInsertMode = sectionInsertMode;
_sectionOptions = sectionOptions;
_title = title;
if ([self canInsertUsingButton]){
_multivaluedAddButton = [XLFormRowDescriptor formRowDescriptorWithTag:nil rowType:XLFormRowDescriptorTypeButton title:@"Add Item"];
if ([self canInsertUsingButton]) {
_multivaluedAddButton = [XLFormRowDescriptor formRowDescriptorWithTag:nil
rowType:XLFormRowDescriptorTypeButton
title:@"Add Item"];
[_multivaluedAddButton.cellConfig setObject:@(NSTextAlignmentNatural) forKey:@"textLabel.textAlignment"];
_multivaluedAddButton.action.formSelector = NSSelectorFromString(@"multivaluedInsertButtonTapped:");
[self insertObject:_multivaluedAddButton inFormRowsAtIndex:0];
[self insertObject:_multivaluedAddButton inAllRowsAtIndex:0];
}
}
return self;
}
@@ -125,14 +136,12 @@
-(void)addFormRow:(XLFormRowDescriptor *)formRow
{
NSUInteger index;
NSUInteger index = [self.allRows count];
if ([self canInsertUsingButton]) {
index = ([self.formRows count] > 0) ? [self.formRows count] - 1 : 0;
} else {
index = [self.allRows count];
}
[self insertObject:formRow inAllRowsAtIndex:index];
}
@@ -144,26 +153,23 @@
}
else { //case when afterRow does not exist. Just insert at the end.
[self addFormRow:formRow];
return;
}
}
-(void)addFormRow:(XLFormRowDescriptor *)formRow beforeRow:(XLFormRowDescriptor *)beforeRow
{
NSUInteger allRowIndex = [self.allRows indexOfObject:beforeRow];
if (allRowIndex != NSNotFound) {
[self insertObject:formRow inAllRowsAtIndex:allRowIndex];
}
else { //case when afterRow does not exist. Just insert at the end.
[self addFormRow:formRow];
return;
}
}
-(void)removeFormRowAtIndex:(NSUInteger)index
{
if (self.formRows.count > index){
if (self.formRows.count > index) {
XLFormRowDescriptor *formRow = [self.formRows objectAtIndex:index];
NSUInteger allRowIndex = [self.allRows indexOfObject:formRow];
[self removeObjectFromFormRowsAtIndex:index];
@@ -174,21 +180,21 @@
-(void)removeFormRow:(XLFormRowDescriptor *)formRow
{
NSUInteger index = NSNotFound;
if ((index = [self.formRows indexOfObject:formRow]) != NSNotFound){
if ((index = [self.formRows indexOfObject:formRow]) != NSNotFound) {
[self removeFormRowAtIndex:index];
}
else if ((index = [self.allRows indexOfObject:formRow]) != NSNotFound){
if (self.allRows.count > index){
else if ((index = [self.allRows indexOfObject:formRow]) != NSNotFound) {
if (self.allRows.count > index) {
[self removeObjectFromAllRowsAtIndex:index];
}
};
}
}
- (void)moveRowAtIndexPath:(NSIndexPath *)sourceIndex toIndexPath:(NSIndexPath *)destinationIndex
{
if ((sourceIndex.row < self.formRows.count) && (destinationIndex.row < self.formRows.count) && (sourceIndex.row != destinationIndex.row)){
XLFormRowDescriptor * row = [self objectInFormRowsAtIndex:sourceIndex.row];
XLFormRowDescriptor * destRow = [self objectInFormRowsAtIndex:destinationIndex.row];
if ((sourceIndex.row < self.formRows.count) && (destinationIndex.row < self.formRows.count) && (sourceIndex.row != destinationIndex.row)) {
XLFormRowDescriptor *row = [self objectInFormRowsAtIndex:sourceIndex.row];
XLFormRowDescriptor *destRow = [self objectInFormRowsAtIndex:destinationIndex.row];
[self.formRows removeObjectAtIndex:sourceIndex.row];
[self.formRows insertObject:row atIndex:destinationIndex.row];
@@ -199,11 +205,15 @@
-(void)dealloc
{
[self removeObserver:self forKeyPath:XLFormRowsKey];
[self.formDescriptor removeObserversOfObject:self predicateType:XLPredicateTypeHidden];
@try {
[self removeObserver:self forKeyPath:@"formRows"];
}
@catch (NSException * __unused exception) {}
[self.formRows removeAllObjects];
self.formRows = nil;
[self.allRows removeAllObjects];
self.allRows = nil;
}
#pragma mark - Show/hide rows
@@ -214,13 +224,15 @@
if (formIndex != NSNotFound) {
return;
}
NSUInteger index = [self.allRows indexOfObject:formRow];
if (index != NSNotFound){
if (index != NSNotFound) {
while (formIndex == NSNotFound && index > 0) {
XLFormRowDescriptor* previous = [self.allRows objectAtIndex:--index];
formIndex = [self.formRows indexOfObject:previous];
}
if (formIndex == NSNotFound){ // index == 0 => insert at the beginning
if (formIndex == NSNotFound) { // index == 0 => insert at the beginning
[self insertObject:formRow inFormRowsAtIndex:0];
}
else {
@@ -232,36 +244,41 @@
-(void)hideFormRow:(XLFormRowDescriptor*)formRow{
NSUInteger index = [self.formRows indexOfObject:formRow];
if (index != NSNotFound){
if (index != NSNotFound) {
[self removeObjectFromFormRowsAtIndex:index];
}
}
#pragma mark - KVO
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- (void)observeValueForKeyPath:(nullable NSString *)keyPath
ofObject:(nullable id)object
change:(nullable NSDictionary<NSKeyValueChangeKey, id> *)change
context:(nullable void *)context
{
if (!self.formDescriptor.delegate) return;
if ([keyPath isEqualToString:@"formRows"]){
if ([self.formDescriptor.formSections containsObject:self]){
if ([[change objectForKey:NSKeyValueChangeKindKey] isEqualToNumber:@(NSKeyValueChangeInsertion)]){
NSIndexSet * indexSet = [change objectForKey:NSKeyValueChangeIndexesKey];
XLFormRowDescriptor * formRow = [((XLFormSectionDescriptor *)object).formRows objectAtIndex:indexSet.firstIndex];
if (!self.formDescriptor.delegate) {
return;
}
else if ([keyPath isEqualToString:XLFormRowsKey]) {
if ([self.formDescriptor.formSections containsObject:self]) {
if ([[change objectForKey:NSKeyValueChangeKindKey] isEqualToNumber:@(NSKeyValueChangeInsertion)]) {
NSIndexSet *indexSet = [change objectForKey:NSKeyValueChangeIndexesKey];
XLFormRowDescriptor *formRow = [((XLFormSectionDescriptor *)object).formRows objectAtIndex:indexSet.firstIndex];
NSUInteger sectionIndex = [self.formDescriptor.formSections indexOfObject:object];
[self.formDescriptor.delegate formRowHasBeenAdded:formRow atIndexPath:[NSIndexPath indexPathForRow:indexSet.firstIndex inSection:sectionIndex]];
[self.formDescriptor.delegate formRowHasBeenAdded:formRow
atIndexPath:[NSIndexPath indexPathForRow:indexSet.firstIndex inSection:sectionIndex]];
}
else if ([[change objectForKey:NSKeyValueChangeKindKey] isEqualToNumber:@(NSKeyValueChangeRemoval)]){
NSIndexSet * indexSet = [change objectForKey:NSKeyValueChangeIndexesKey];
XLFormRowDescriptor * removedRow = [[change objectForKey:NSKeyValueChangeOldKey] objectAtIndex:0];
else if ([[change objectForKey:NSKeyValueChangeKindKey] isEqualToNumber:@(NSKeyValueChangeRemoval)]) {
NSIndexSet *indexSet = [change objectForKey:NSKeyValueChangeIndexesKey];
XLFormRowDescriptor *removedRow = [[change objectForKey:NSKeyValueChangeOldKey] objectAtIndex:0];
NSUInteger sectionIndex = [self.formDescriptor.formSections indexOfObject:object];
[self.formDescriptor.delegate formRowHasBeenRemoved:removedRow atIndexPath:[NSIndexPath indexPathForRow:indexSet.firstIndex inSection:sectionIndex]];
[self.formDescriptor.delegate formRowHasBeenRemoved:removedRow
atIndexPath:[NSIndexPath indexPathForRow:indexSet.firstIndex inSection:sectionIndex]];
}
}
}
}
#pragma mark - KVC
-(NSUInteger)countOfFormRows
@@ -342,9 +359,9 @@
-(void)setHidePredicateCache:(NSNumber *)hidePredicateCache
{
NSParameterAssert(hidePredicateCache);
NSParameterAssert(hidePredicateCache != nil);
self.isDirtyHidePredicateCache = NO;
if (!_hidePredicateCache || ![_hidePredicateCache isEqualToNumber:hidePredicateCache]){
if (_hidePredicateCache == nil || ![_hidePredicateCache isEqualToNumber:hidePredicateCache]) {
_hidePredicateCache = hidePredicateCache;
}
}
@@ -354,6 +371,7 @@
if (self.isDirtyHidePredicateCache) {
return [self evaluateIsHidden];
}
return [self.hidePredicateCache boolValue];
}
@@ -362,7 +380,8 @@
if ([_hidden isKindOfClass:[NSPredicate class]]) {
if (!self.formDescriptor) {
self.isDirtyHidePredicateCache = YES;
} else {
}
else {
@try {
self.hidePredicateCache = @([_hidden evaluateWithObject:self substitutionVariables:self.formDescriptor.allRowsByTag ?: @{}]);
}
@@ -372,21 +391,24 @@
};
}
}
else{
else {
self.hidePredicateCache = _hidden;
}
if ([self.hidePredicateCache boolValue]){
if ([self.formDescriptor.delegate isKindOfClass:[XLFormViewController class]]){
XLFormBaseCell* firtResponder = (XLFormBaseCell*) [((XLFormViewController*)self.formDescriptor.delegate).tableView findFirstResponder];
if ([firtResponder isKindOfClass:[XLFormBaseCell class]] && firtResponder.rowDescriptor.sectionDescriptor == self){
if ([self.hidePredicateCache boolValue]) {
if ([self.formDescriptor.delegate isKindOfClass:[XLFormViewController class]]) {
XLFormBaseCell *firtResponder = (XLFormBaseCell *)[((XLFormViewController *)self.formDescriptor.delegate).tableView findFirstResponder];
if ([firtResponder isKindOfClass:[XLFormBaseCell class]] && firtResponder.rowDescriptor.sectionDescriptor == self) {
[firtResponder resignFirstResponder];
}
}
[self.formDescriptor hideFormSection:self];
}
else{
else {
[self.formDescriptor showFormSection:self];
}
return [self.hidePredicateCache boolValue];
}
@@ -398,13 +420,15 @@
-(void)setHidden:(id)hidden
{
if ([_hidden isKindOfClass:[NSPredicate class]]){
if ([_hidden isKindOfClass:[NSPredicate class]]) {
[self.formDescriptor removeObserversOfObject:self predicateType:XLPredicateTypeHidden];
}
_hidden = [hidden isKindOfClass:[NSString class]] ? [hidden formPredicate] : hidden;
if ([_hidden isKindOfClass:[NSPredicate class]]){
if ([_hidden isKindOfClass:[NSPredicate class]]) {
[self.formDescriptor addObserversOfObject:self predicateType:XLPredicateTypeHidden];
}
[self evaluateIsHidden]; // check and update if this row should be hidden.
}
+1 -1
View File
@@ -28,7 +28,7 @@
@interface UIView (XLFormAdditions)
+(id)autolayoutView;
+(instancetype)autolayoutView;
-(NSLayoutConstraint *)layoutConstraintSameHeightOf:(UIView *)view;
-(UIView *)findFirstResponder;
-(UITableViewCell<XLFormDescriptorCell> *)formDescriptorCell;
+34 -19
View File
@@ -27,47 +27,62 @@
@implementation UIView (XLFormAdditions)
+ (id)autolayoutView
+ (instancetype)autolayoutView
{
UIView *view = [self new];
__kindof UIView *view = [self new];
view.translatesAutoresizingMaskIntoConstraints = NO;
return view;
}
-(NSLayoutConstraint *)layoutConstraintSameHeightOf:(UIView *)view
- (NSLayoutConstraint *)layoutConstraintSameHeightOf:(UIView *)view
{
return [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeHeight multiplier:1.0f constant:0.0f];
return [NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:view
attribute:NSLayoutAttributeHeight
multiplier:1.0
constant:0.0];
}
- (UIView *)findFirstResponder
{
UIView *firstResponder = nil;
if (self.isFirstResponder) {
return self;
firstResponder = self;
}
for (UIView *subView in self.subviews) {
UIView *firstResponder = [subView findFirstResponder];
if (firstResponder != nil) {
return firstResponder;
else {
for (UIView *subView in self.subviews) {
UIView *fr = [subView findFirstResponder];
if (fr != nil) {
firstResponder = fr;
break;
}
}
}
return nil;
return firstResponder;
}
- (UITableViewCell<XLFormDescriptorCell> *)formDescriptorCell
{
UITableViewCell<XLFormDescriptorCell> * tableViewCell = nil;
if ([self isKindOfClass:[UITableViewCell class]]) {
if ([self conformsToProtocol:@protocol(XLFormDescriptorCell)]){
return (UITableViewCell<XLFormDescriptorCell> *)self;
}
return nil;
}
if (self.superview) {
UITableViewCell<XLFormDescriptorCell> * tableViewCell = [self.superview formDescriptorCell];
if (tableViewCell != nil) {
return tableViewCell;
tableViewCell = (UITableViewCell<XLFormDescriptorCell> *)self;
}
}
return nil;
else if (self.superview) {
UITableViewCell<XLFormDescriptorCell> * cell = [self.superview formDescriptorCell];
if (cell != nil) {
tableViewCell = cell;
}
}
return tableViewCell;
}
@end
@@ -27,8 +27,8 @@
@interface XLFormRowNavigationAccessoryView : UIToolbar
@property (nonatomic) UIBarButtonItem *previousButton;
@property (nonatomic) UIBarButtonItem *nextButton;
@property (nonatomic) UIBarButtonItem *doneButton;
@property (nonatomic, weak) UIBarButtonItem *previousButton;
@property (nonatomic, weak) UIBarButtonItem *nextButton;
@property (nonatomic, weak) UIBarButtonItem *doneButton;
@end
@@ -25,14 +25,6 @@
#import "XLFormRowNavigationAccessoryView.h"
@interface XLFormRowNavigationAccessoryView ()
@property (nonatomic) UIBarButtonItem *fixedSpace;
@property (nonatomic) UIBarButtonItem *flexibleSpace;
@end
@implementation XLFormRowNavigationAccessoryView
@synthesize previousButton = _previousButton;
@@ -44,55 +36,30 @@
{
self = [super initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44.0)];
if (self) {
UIBarButtonItem *previousButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:105 target:nil action:nil];
_previousButton = previousButton;
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:106 target:nil action:nil];
_nextButton = nextButton;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:nil action:nil];
_doneButton = doneButton;
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpace.width = 22.0;
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
self.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth);
NSArray * items = [NSArray arrayWithObjects:self.previousButton,
self.fixedSpace,
self.nextButton,
self.flexibleSpace,
self.doneButton, nil];
NSArray * items = [NSArray arrayWithObjects:previousButton,
fixedSpace,
nextButton,
flexibleSpace,
doneButton, nil];
[self setItems:items];
}
return self;
}
#pragma mark - Properties
-(UIBarButtonItem *)previousButton
{
if (_previousButton) return _previousButton;
_previousButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:105 target:nil action:nil];
return _previousButton;
}
-(UIBarButtonItem *)fixedSpace
{
if (_fixedSpace) return _fixedSpace;
_fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
_fixedSpace.width = 22.0;
return _fixedSpace;
}
-(UIBarButtonItem *)nextButton
{
if (_nextButton) return _nextButton;
_nextButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:106 target:nil action:nil];
return _nextButton;
}
-(UIBarButtonItem *)flexibleSpace
{
if (_flexibleSpace) return _flexibleSpace;
_flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
return _flexibleSpace;
}
-(UIBarButtonItem *)doneButton
{
if (_doneButton) return _doneButton;
_doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:nil action:nil];
return _doneButton;
}
#pragma mark - Helpers
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event
+3 -3
View File
@@ -29,9 +29,9 @@
@interface XLFormTextView : UITextView
@property (nonatomic) NSString *placeholder;
@property (nonatomic) UIColor *placeholderColor;
@property (nonatomic, copy) NSString *placeholder;
@property (nonatomic, copy) UIColor *placeholderColor;
@property (readonly) UILabel *placeHolderLabel;
@property (nonatomic, readonly, weak) UILabel *placeHolderLabel;
@end
+11 -9
View File
@@ -30,7 +30,7 @@
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidChangeNotification object:nil];
}
- (instancetype)initWithFrame:(CGRect)frame
@@ -67,17 +67,19 @@
{
if([[self placeholder] length] > 0){
if (_placeHolderLabel == nil ){
_placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(4,8,self.bounds.size.width - 16,0)];
_placeHolderLabel.lineBreakMode = NSLineBreakByWordWrapping;
_placeHolderLabel.numberOfLines = 0;
_placeHolderLabel.backgroundColor = [UIColor clearColor];
_placeHolderLabel.textColor = self.placeholderColor;
_placeHolderLabel.alpha = 0;
_placeHolderLabel.tag = 999;
[self addSubview:_placeHolderLabel];
UILabel *placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(4,8,self.bounds.size.width - 16,0)];
placeHolderLabel.lineBreakMode = NSLineBreakByWordWrapping;
placeHolderLabel.numberOfLines = 0;
placeHolderLabel.backgroundColor = [UIColor clearColor];
placeHolderLabel.textColor = self.placeholderColor;
placeHolderLabel.alpha = 0;
placeHolderLabel.tag = 999;
[self addSubview:placeHolderLabel];
_placeHolderLabel = placeHolderLabel;
}
_placeHolderLabel.text = self.placeholder;
_placeHolderLabel.font = self.font;
_placeHolderLabel.textColor = self.placeholderColor;
[_placeHolderLabel sizeToFit];
[self sendSubviewToBack:_placeHolderLabel];
}
+2 -2
View File
@@ -29,8 +29,8 @@
@interface XLFormRegexValidator : XLFormValidator
@property NSString *msg;
@property NSString *regex;
@property (nonatomic, copy) NSString *msg;
@property (nonatomic, copy) NSString *regex;
- (instancetype)initWithMsg:(NSString*)msg andRegexString:(NSString*)regex;
+ (XLFormRegexValidator *)formRegexValidatorWithMsg:(NSString *)msg regex:(NSString *)regex;
@@ -29,8 +29,8 @@
@interface XLFormValidationStatus : NSObject
@property NSString *msg;
@property BOOL isValid;
@property (nonatomic, copy) NSString *msg;
@property (nonatomic, assign) BOOL isValid;
@property (nonatomic, weak) XLFormRowDescriptor *rowDescriptor;
//-(instancetype)initWithMsg:(NSString*)msg andStatus:(BOOL)isValid;