iphone - Dynamic, localized NSString -
I need to create an NSString similar to the following:
Name: Craig Buchanan
Telephone: 800-555-1212
Email: name@company.com
Where:
- Each row (such as a telephone) is included or
- The main part of the string (i.e. the part of ':' on the left side) is localized
- The portion of the value is from UITextField.
My approach:
NSMutableArray * value = [[NSMutableArray alloc] initWithCapacity: 3]; If (self.nameSwitch.isOn) [values addObject: [NSString stringWithFormat: @ "% @:% @", NSLocalizedString (@ "name", @ "name label"), textFieldName.text]]; If (self.telephoneswitch.isOn) [values addObject: [NSString stringWithFormat: @ "% @:% @", NSLocalizedString (@ "telephone", @ "telephone number label"), textFieldTelephone.text]]; If (self.emailSwitch.isOn) [values addObject: [NSString stringWithFormat: @ "% @:% @", NSLocalizedString (@ "email", @ "email address label"), textFieldEmail.text]]; Return [Value ComponentsGuidebrighting: @ "\ r"];
I have a few questions:
- Is this a decent approach (I am an objective-Noble Noble)?
- I know that my array is autorealle, but still I am worried about memory usage should I release the auto release pool? Looks a little dangerous.
- I'm hoping to make the code a bit more dynamic. My initial idea is to create an array of outlet variables, then use the UISwitch to store that key that drives localization. idea?
Thank you for your time,
Craig Buchanan
Colonos can not be used in your target language, so simply add local lines to call like this: For Autorelease question, you can create a local auto-pool pool: Finally, you can use the tag of the switch to point to an array index. If you do this, you will not need the
NSAutoreleasePool * myPool = [[NSAUTOriasius Alok] init]; // to work. [MyPool Release];
IBOutlet
variable to switch; You can only use -viewForTag:
or the arguments in the action method. You can use NSIndexSet
to store state switches if you wish. But if you want to be dynamic, you should probably use a table to catch the switch. If you do this, you can use table row numbers instead of tags.
Comments
Post a Comment