UA-17470720-3

Jump to content


Photo
- - - - -

Setting the keyboard type for a text field cell


  • Please log in to reply
8 replies to this topic

#1 Peter Simmons

Peter Simmons

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 14 posts
Reputation: 2
Good

Posted 18 February 2012 - 01:48 AM

Hi,

I found the need to set a keyboard type for a text field. My use case is a phone number field the underlying type is string (formatting phone numbers) but I wanted an easy way to restrict to useful numbers so I know I can send to the phone app later.

I looked in the forum and didn't see a complete answer. Usually I can use the delegate hooks to customise but I found it hard to work out which cell was which and then just figured it'd be better if we could set the keyboard type with attributes similar to autocorrection type for example. Blow is the commit details from my local project which shows what I did.

Anyone is free to use my changes as long as it doesn't break sensible table view license it self. Also any feedback welcome and I hope this can be included in a future version if it hasn't already made it into the 3.0 code.

if there was already a way to do this let me know also as I am pretty new to STV but enjoying it so far.

Cheers,
Pete

commit 5bd294fc669bf09aedc0233140de588640f7c4af
Author: Peter Simmons
Date: Sat Feb 18 16:07:45 2012 +1300

Augumenting SCTextFieldAttributes and SCTextFieldCell to allow setting the keyboard type via attributes on a propertydef.

diff --git a/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.h b/PillReminder/Libraries/Sensible TableView/SCPropertyAttr
index 04d37ae..26396ef 100644
--- a/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.h
+++ b/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.h
@@ -186,6 +186,36 @@
/** The auto-capitalization style for the text field. Default: UITextAutocapitalizationTypeSentences. */
@property (nonatomic, readwrite) UITextAutocapitalizationType autocapitalizationType;

+/**********
+ * PS Added
+ *********/
+@property (nonatomic, readwrite) UIKeyboardType keyboardType;
+
+/** Allocates and returns an initialized 'SCTextFieldAttributes'.
+ *
+ * @param _placeholder The placeholder of the generated UITextField control. Set to nil to ignore.
+ * @param secure Identifies whether the text field should hide the text being entered.
+ * @param autocorrection The auto-correction style for the text field.
+ * @param autocapitalization The auto-capitalization style for the text field.
+ * @param keyboardType The keyboard type for the text field.
+ */
++ (id)attributesWithPlaceholder:(NSString *)_placeholder secureTextEntry:(BOOL)secure autocorrectionType:(UITextAutocorrectionType)auto
+
+/** Returns an initialized 'SCTextFieldAttributes'.
+ *
+ * @param _placeholder The placeholder of the generated UITextField control. Set to nil to ignore.
+ * @param secure Identifies whether the text field should hide the text being entered.
+ * @param autocorrection The auto-correction style for the text field.
+ * @param autocapitalization The auto-capitalization style for the text field.
+ * @param keyboardType The keyboard type for the text field.
+ */
+- (id)initWithPlaceholder:(NSString *)_placeholder secureTextEntry:(BOOL)secure autocorrectionType:(UITextAutocorrectionType)autocorrec
+
+/**********
+ * End PS Added
+ *********/
+
+
@end


diff --git a/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.m b/PillReminder/Libraries/Sensible TableView/SCPropertyAttr
index cfe4481..acf34dc 100644
--- a/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.m
+++ b/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.m
@@ -121,6 +121,29 @@
@synthesize autocorrectionType;
@synthesize autocapitalizationType;

+/**********
+ * PS Added
+ *********/
+
+@synthesize keyboardType;
+
++ (id)attributesWithPlaceholder:(NSString *)_placeholder secureTextEntry:(BOOL)secure autocorrectionType:(UITextAutocorrectionType)auto
+ return SC_Autorelease([[[self class] alloc] initWithPlaceholder:_placeholder secureTextEntry:secure autocorrectionType:autocorrecti
+}
+
+- (id)initWithPlaceholder:(NSString *)_placeholder secureTextEntry:(BOOL)secure autocorrectionType:(UITextAutocorrectionType)autocorrec
+ if ((self=[self initWithPlaceholder:_placeholder secureTextEntry:secure autocorrectionType:autocorrection autocapitalizationType:au
+ keyboardType = _keyboardType;
+ }
+ return self;
+}
+
+
+/**********
+ * End PS Added
+ *********/
+
+
+ (id)attributesWithPlaceholder:(NSString *)_placeholder
{
return SC_Autorelease([[[self class] alloc] initWithPlaceholder:_placeholder]);
@@ -139,6 +162,14 @@
secureTextEntry = FALSE;
Date: Sat Feb 18 16:07:45 2012 +1300

Augumenting SCTextFieldAttributes and SCTextFieldCell to allow setting the keyboard type via attributes on a propertydef.

diff --git a/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.h b/PillReminder/Libraries/Sensible TableView/SCPropertyAttr
index 04d37ae..26396ef 100644
--- a/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.h
+++ b/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.h
@@ -186,6 +186,36 @@
/** The auto-capitalization style for the text field. Default: UITextAutocapitalizationTypeSentences. */
@property (nonatomic, readwrite) UITextAutocapitalizationType autocapitalizationType;

+/**********
+ * PS Added
+ *********/
+@property (nonatomic, readwrite) UIKeyboardType keyboardType;
+
+/** Allocates and returns an initialized 'SCTextFieldAttributes'.
+ *
+ * @param _placeholder The placeholder of the generated UITextField control. Set to nil to ignore.
+ * @param secure Identifies whether the text field should hide the text being entered.
+ * @param autocorrection The auto-correction style for the text field.
+ * @param autocapitalization The auto-capitalization style for the text field.
+ * @param keyboardType The keyboard type for the text field.
+ */
++ (id)attributesWithPlaceholder:(NSString *)_placeholder secureTextEntry:(BOOL)secure autocorrectionType:(UITextAutocorrectionType)auto
+
+/** Returns an initialized 'SCTextFieldAttributes'.
+ *
+ * @param _placeholder The placeholder of the generated UITextField control. Set to nil to ignore.
+ * @param secure Identifies whether the text field should hide the text being entered.
+ * @param autocorrection The auto-correction style for the text field.
+ * @param autocapitalization The auto-capitalization style for the text field.
+ * @param keyboardType The keyboard type for the text field.
+ */
+- (id)initWithPlaceholder:(NSString *)_placeholder secureTextEntry:(BOOL)secure autocorrectionType:(UITextAutocorrectionType)autocorrec
+
+/**********
+ * End PS Added
+ *********/
+
+
@end


diff --git a/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.m b/PillReminder/Libraries/Sensible TableView/SCPropertyAttr
index cfe4481..acf34dc 100644
--- a/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.m
+++ b/PillReminder/Libraries/Sensible TableView/SCPropertyAttributes.m
@@ -121,6 +121,29 @@
@synthesize autocorrectionType;
@synthesize autocapitalizationType;

+/**********
+ * PS Added
+ *********/
+
+@synthesize keyboardType;
+
++ (id)attributesWithPlaceholder:(NSString *)_placeholder secureTextEntry:(BOOL)secure autocorrectionType:(UITextAutocorrectionType)auto
+ return SC_Autorelease([[[self class] alloc] initWithPlaceholder:_placeholder secureTextEntry:secure autocorrectionType:autocorrecti
+}
+
+- (id)initWithPlaceholder:(NSString *)_placeholder secureTextEntry:(BOOL)secure autocorrectionType:(UITextAutocorrectionType)autocorrec
+ if ((self=[self initWithPlaceholder:_placeholder secureTextEntry:secure autocorrectionType:autocorrection autocapitalizationType:au
+ keyboardType = _keyboardType;
+ }
+ return self;
+}
+
+
+/**********
+ * End PS Added
+ *********/
+
+
+ (id)attributesWithPlaceholder:(NSString *)_placeholder
{
return SC_Autorelease([[[self class] alloc] initWithPlaceholder:_placeholder]);
@@ -139,6 +162,14 @@
secureTextEntry = FALSE;
autocorrectionType = UITextAutocorrectionTypeDefault;
autocapitalizationType = UITextAutocapitalizationTypeSentences;
+ /**********
+ * PS Added
+ *********/
+ keyboardType = UIKeyboardTypeDefault;
+ /**********
+ * End PS Added
+ *********/
+
}
return self;
}
diff --git a/PillReminder/Libraries/Sensible TableView/SCTableViewCell.m b/PillReminder/Libraries/Sensible TableView/SCTableViewCell.m
index 38cf094..823da3a 100644
--- a/PillReminder/Libraries/Sensible TableView/SCTableViewCell.m
+++ b/PillReminder/Libraries/Sensible TableView/SCTableViewCell.m
@@ -1940,6 +1940,14 @@
self.textField.secureTextEntry = textFieldAttributes.secureTextEntry;
self.textField.autocorrectionType = textFieldAttributes.autocorrectionType;
self.textField.autocapitalizationType = textFieldAttributes.autocapitalizationType;
+
+ /**********
+ * PS Added
+ *********/
+ self.textField.keyboardType = textFieldAttributes.keyboardType;
+ /**********
+ * End PS Added
+ *********/
}

//overrides superclass

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 19 February 2012 - 11:06 PM

Hi Peter and welcome to our forums! :)

Thank you very much for your feedback, we really appreciate it! We'll definitely be incorporating the ability to do this in our next release. Thanks again!

#3 Richard Williams

Richard Williams

    Starting Out

  • STV 2.0
  • Pip
  • 9 posts
Reputation: 0
Neutral

Posted 01 March 2012 - 10:59 PM

Just got Sensible TableView yesterday.

Great product, but I to could really do with the ability to specify the keyboard.

I assume my license means I'll be able to download the new release?

Thanks :)

#4 Peter Simmons

Peter Simmons

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 14 posts
Reputation: 2
Good

Posted 01 March 2012 - 11:06 PM

You could apply the diff I posted above in the mean time.
  • David DelMonte likes this

#5 Richard Williams

Richard Williams

    Starting Out

  • STV 2.0
  • Pip
  • 9 posts
Reputation: 0
Neutral

Posted 01 March 2012 - 11:09 PM

You could apply the diff I posted above in the mean time.


Thanks, I'd consider that but I'm not familiar with how... guess I need a diff tool.

Only been doing ObjC/xCode/iOS for about 10 days, PHP for some time though.

#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 03 March 2012 - 05:12 PM

Hi Richard,

Are you creating the cells directly, or are they automatically generated for you? @cabbiepete's solution is for automatically generated cells. For cells you add directly, you can easily do this:
myTextFieldCell.textField.keyboardType = UIKeyboardTypeDefault; // set your preferred type here
Hope this helps!
  • aaronium112 likes this

#7 Richard Williams

Richard Williams

    Starting Out

  • STV 2.0
  • Pip
  • 9 posts
Reputation: 0
Neutral

Posted 03 March 2012 - 05:58 PM

Perfect, thanks very much :)

#8 Steve McKenna

Steve McKenna

    Sr. Member

  • STV 4.0 Pro
  • PipPipPip
  • 32 posts
Reputation: 4
Good

Posted 14 May 2012 - 08:19 AM

Tarekskr - is this feature if v3? If so, how does it work? I'm using coredata but also have a need to set the keyboard for phone numbers etc.
Thanks
Steve

#9 Steve McKenna

Steve McKenna

    Sr. Member

  • STV 4.0 Pro
  • PipPipPip
  • 32 posts
Reputation: 4
Good

Posted 15 May 2012 - 05:28 AM

tarekskr replied to a different question I had.
Based on his response I was able to solve this problem using v3 with the following code.
Hope it helps you out too.

SCPropertyDefinition *namePDef = [witnessDef propertyDefinitionWithName:@"phone"];
	namePDef.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
	{
		SCTextFieldCell *textFieldCell = (SCTextFieldCell *)cell;
		textFieldCell.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
	};

  • Jeremie Weldin and Teoni Valois like this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users