Skip to content

Commit

Permalink
Updated to version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Mar 14, 2014
1 parent 1f3d682 commit 5b494b4
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Examples/BasicExample/BasicExample/RegistrationForm.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ - (NSArray *)fields
@"password",
@"repeatPassword",

//we want to add another group header here
//we want to add another group header here, and modify the auto-capitalization

@{FXFormFieldKey: @"name", FXFormFieldHeader: @"Details"},
@{FXFormFieldKey: @"name", FXFormFieldHeader: @"Details",
@"textField.autocapitalizationType": @(UITextAutocapitalizationTypeWords)},

//this is a multiple choice field, so we'll need to provide some options
//because this is an enum property, the indexes of the options should match enum values
Expand Down
4 changes: 2 additions & 2 deletions FXForms.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = 'FXForms'
s.version = '1.0.1'
s.version = '1.0.2'
s.license = 'zlib'
s.summary = 'FXForms is an Objective-C library for easily creating table-based forms on iOS. It is ideal for settings pages, or user data entry tasks.'
s.homepage = 'https://github.com/nicklockwood/FXForms'
s.authors = 'Nick Lockwood'
s.source = { :git => "https://github.com/nicklockwood/FXForms.git", :tag => "1.0.1" }
s.source = { :git => "https://github.com/nicklockwood/FXForms.git", :tag => "1.0.2" }
s.source_files = 'FXForms'
s.requires_arc = true
s.ios.deployment_target = '5.0'
Expand Down
2 changes: 1 addition & 1 deletion FXForms/FXForms.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FXForms.h
//
// Version 1.0.1
// Version 1.0.2
//
// Created by Nick Lockwood on 13/02/2014.
// Copyright (c) 2014 Charcoal Design. All rights reserved.
Expand Down
44 changes: 38 additions & 6 deletions FXForms/FXForms.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FXForms.m
//
// Version 1.0.1
// Version 1.0.2
//
// Created by Nick Lockwood on 13/02/2014.
// Copyright (c) 2014 Charcoal Design. All rights reserved.
Expand Down Expand Up @@ -1196,6 +1196,33 @@ - (void)setUp
[self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self.textField action:NSSelectorFromString(@"becomeFirstResponder")]];
}

- (void)setValue:(id)value forKeyPath:(NSString *)keyPath
{
//TODO: is there a less hacky fix for this?
static NSDictionary *specialCases = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
specialCases = @{@"textField.autocapitalizationType": ^(UITextField *f, NSInteger v){ f.autocapitalizationType = v; },
@"textField.autocorrectionType": ^(UITextField *f, NSInteger v){ f.autocorrectionType = v; },
@"textField.spellCheckingType": ^(UITextField *f, NSInteger v){ f.spellCheckingType = v; },
@"textField.keyboardType": ^(UITextField *f, NSInteger v){ f.keyboardType = v; },
@"textField.keyboardAppearance": ^(UITextField *f, NSInteger v){ f.keyboardAppearance = v; },
@"textField.returnKeyType": ^(UITextField *f, NSInteger v){ f.returnKeyType = v; },
@"textField.enablesReturnKeyAutomatically": ^(UITextField *f, NSInteger v){ f.enablesReturnKeyAutomatically = !!v; },
@"textField.secureTextEntry": ^(UITextField *f, NSInteger v){ f.secureTextEntry = !!v; }};
});

void (^block)(UITextField *f, NSInteger v) = specialCases[keyPath];
if (block)
{
block(self.textField, [value integerValue]);
}
else
{
[super setValue:value forKeyPath:keyPath];
}
}

- (void)layoutSubviews
{
[super layoutSubviews];
Expand Down Expand Up @@ -1271,22 +1298,27 @@ - (BOOL)textFieldShouldReturn:(__unused UITextField *)textField

- (void)textFieldDidEndEditing:(__unused UITextField *)textField
{
id value = self.textField.text;
if ([self.field.type isEqualToString:FXFormFieldTypeNumber])
{
self.field.value = @([self.textField.text doubleValue]);
value = @([self.textField.text doubleValue]);
}
else if ([self.field.type isEqualToString:FXFormFieldTypeInteger])
{
self.field.value = @([self.textField.text integerValue]);
value = @([self.textField.text longLongValue]);
}
else if ([self.field.valueClass isSubclassOfClass:[NSURL class]])
{
self.field.value = [self.field.valueClass URLWithString:self.textField.text];
value = [self.field.valueClass URLWithString:self.textField.text];
}
else

//handle case where value is numeric but value class is string
if (![value isKindOfClass:[NSString class]] && [self.field.valueClass isSubclassOfClass:[NSString class]])
{
self.field.value = self.textField.text;
value = [self.field.valueClass stringWithString:[value description]];
}

self.field.value = value;
[self.field performActionWithResponder:self sender:self];
}

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FXForms

version 1.0.1, March 9th, 2014
version 1.0.2, March 14th, 2014

Copyright (C) 2014 Charcoal Design

Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Unlike other solutions, FXForms works directly with strongly-typed data models t
Supported iOS & SDK Versions
-----------------------------

* Supported build target - iOS 7.0 (Xcode 5.0)
* Supported build target - iOS 7.1 (Xcode 5.1)
* Earliest supported deployment target - iOS 5.0
* Earliest compatible deployment target - iOS 5.0

Expand Down Expand Up @@ -375,8 +375,17 @@ If you want to tweak some properties of the field cells, without subclassing the
return @{@"textLabel.color": [UIColor redColor]};
}
```

This code would disable auto-capitalisation for the name field:

```objc
- (NSDictionary *)nameField
{
return @{@"textField.autocapitalizationType": @(UITextAutocapitalizationTypeNone)};
}
```

Cells are not recycled in the FXForm controller, so you don't need to worry about cleaning up any properties that you set in this way.
Cells are not recycled in the FXForm controller, so you don't need to worry about cleaning up any properties that you set in this way. Be careful of overusing "stringly typed" code such as this however as errors can't be caught at compile time. For heavy customisation, it is better to create cell subclasses and override properties in the `-setField:` method.


Custom cells
Expand All @@ -386,7 +395,7 @@ FXForms provides default cell implementations for all supported fields. You may

There are two levels of customisation possible for cells. The simplest option is to subclass one of the existing `FXFormCell` classes, which all inherit from `FXFormBaseCell`. These cell classes contain a lot of logic for handling the various different field types, but expose the views and controls used, for easy customisation.

If you already have a base cell class and don't want to base your cells on `FXFormBaseCell`, you can create an FXForms-compatible cell from scratch by subclass `UITableViewCell` and adopting the `FXFormFieldCell` protocol.
If you already have a base cell class and don't want to base your cells on `FXFormBaseCell`, you can create an FXForms-compatible cell from scratch by subclassing `UITableViewCell` and adopting the `FXFormFieldCell` protocol.

Your custom cell must have a property called field, of type `FXFormField`. `FXFormField` is a wrapper class used to encapsulate the properties of a field, and also provides a way to set and get the associated form value (via the field.value virtual property). You cannot instantiate `FXFormField` wrappers directly, however the can be accessed and enumerated via methods on the `FXFormController`. `FXFormField` also provides the `-performActionWithResponder:sender:` that you can use to replicate the cascading action selector behavior of the default cells.

Expand All @@ -400,9 +409,15 @@ Once you have created your custom cell, you can use it as follows:
Release notes
--------------

Version 1.0.2

- Fixed crash when attempting to set UITextInputTraits properties on a FXFormTextFieldCell
- Fixed potential crash when numeric field type is used with string properties

Version 1.0.1

- Subform FXFormController instances now correctly inherit registered cells from the parent controller
- Fields of type FXFormFieldOption with associated actions will now still be toggled before action fires

Version 1.0

Expand Down

0 comments on commit 5b494b4

Please sign in to comment.