ios - Is it somehow possible to define a property in Interface-Builder and read this property in code? -


i have 3 uitextfield's want limit in length. first , second text field 24 characters , third text field 32 characters.

i found this solution limiting characters in uitextfield works fine:

#define maxlength 10  - (bool)textfield:(uitextfield *) textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string {      nsuinteger oldlength = [textfield.text length];     nsuinteger replacementlength = [string length];     nsuinteger rangelength = range.length;      nsuinteger newlength = oldlength - rangelength + replacementlength;      bool returnkey = [string rangeofstring: @"\n"].location != nsnotfound;      return newlength <= maxlength || returnkey; } 

but solution suggests, every text-field limited same length (i.e. 10 characters defined @ top of code snippet). wondering if there chance define kind of property each of text-fields separately in interface-builder of xcode allows me read out in code -- replace "maxlength" "[textfield valueforkey:@"maxlength"]" "maxlength" defined visually in xcode interface-builder...

any ideas?

there's no way define max length each text field through interface builder there simple solution in code.

instead of using #define max length, calculate max length based on textfield parameter.

lets have 3 outlets text fields named field1, field2, , field3. can this:

- (bool)textfield:(uitextfield *) textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string {     nsuinteger maxlength = 24; // field1 , field2     if (textfield == self.field3) {         maxlength = 32;     }      // , rest of processing } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -