Attaching multiple uitextfields to an email - uitextfield

I have multiple UITextFields and I want to attach them to an in app email. I can get one of them appear but not the rest. Here is what I am using.
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
[composer setSubject:#"My Subject"];
[composer setMessageBody:AddNotesTextField.text isHTML:YES];
[self presentModalViewController:composer animated:YES];
[composer release];
Thank you

You got it right already for the body using:
[composer setMessageBody:AddNotesTextField.text isHTML:YES];
So just repeat the procedure with the other fields like so:
[composer setSubject:mySubjectTextField.text];
Or if you are asking how to use the input from multiple text fields into the body of the email, you simply have to use NSString's stringWithFormat:
[composer setMessageBody:[NSString stringWithFormat:#"you can place static %# text in between %# these variables",AddNotesTextField.text,someOtherField.text] isHTML:YES];
In string with format, you escape the default string to add a string using "%#" for every instance where you want to insert some other string. Then after the original string ends you enter the names of the input strings separated by commas. [NSString stringWithFormat:#"%#%#",x,y]

Related

How to trim off symbols from NSNumber?

Im making an iOS app to do with currency. My app receives the value of maybe: $4. This value the app receives is put into an NSNumber. The trouble is the value actualy has a $ in it. How do I trim out the $ in the NSNumber? Or would I be better of putting it into an NSString?
Use NSNumberFormatter:
// set up your number formatter
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
// get a string that you'll be converting to a NSNumber
NSString *myNumberString = [NSString stringWithFormat:#"$4"]
// convert then print to the console
NSNumber *myNumber = [numberFormatter numberFromString:myNumberString];
NSLog(#"myNumber: %#", myNumber);
This should accomplish what you're looking to do. myNumberString will need to be altered to contain whatever string you're receiving.
NSNumberFormatter Documentation: https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSNumberFormatter_Class/Reference/Reference.html

Adding an object to a NSArray

NSString* title = [rescue objectForKey:#"title"];
NSString* name = [rescue objectForKey:#"name"];
NSMutableArray* listBossF = [[NSMutableArray alloc] initWithObjects:#"Hello %# %# I've just arrived"[title, name] ,
#"Hello %# %#everything is fine",
#"Hello %# %# are there any news back at the office?",
#"Hello ( %# %# i arrived at the hotel" ,
#"Hello %# %# I've just arrived at the airport", nil];
Hello im very new to xcode and in fact to programming in general, i've been trying for quite a while to add an object to a specific part of the array (thats why i cant used componentsJoinedByString) but i've had a lot of trouble doing so, the way i'd normally do can anyone tell me what i've been doing wrong? And if i can't add objects to a specific part of an array can anyone possibly give me a suggestion of what i should try? thanks.
You can add an object to a specific part of an array like so:
[array insertObject:#"Hello" atIndex:1]; // After first object in array

Building up an array an element at a time

Currently I'm populating an array in one line, e.g.
self.monthMonths = [[NSArray alloc] initWithObjects:#"January", #"February", #"March", #"April", #"May", #"June",#"July",#"August",#"September",#"October",#"November",#"December", nil];
What is the syntax to add these elements one at a time as I want to pull the data from a database. I'm using the months of the year as an example.
while([results next]) {
NSString *months = [results stringForColumn:#"month"];
self.month = [[NSArray alloc] initWithObjects:#"month",nil];
//[NSArray
NSLog(#"Month: %#",month);
}
Create an NSMutableArray and add the objects to it one by one with addObject
You need to use NSMutableArray instead, and call -addObject:

Setting the text of an NSTextField programmatically

I have a GUI built on IB (Xcode 4).
It has a Static Text field connected to an NSTextField. After reading the information from an XML file it's supposed to change the text to whatever it is coming from the XML
the .h is as follow:
IBOutlet NSTextField * DataBaseLocation;
the .m
NSMutableArray* DBLoc = [[NSMutableArray alloc] initWithCapacity:1];
NSXMLElement* root = [doc rootElement];
NSArray* DBarray = [root nodesForXPath:#"//DataBaseLocation" error:nil];
for(NSXMLElement* xmlElement in DBarray)
[DBLoc addObject:[xmlElement stringValue]];
NSString * DBLocationString = [DBLoc objectAtIndex:0];
[DataBaseLocation setStringValue:DBLocationString];
NSLog(#"DBLoc: %#", DBLoc);
The NSLog shows that DBLoc has the correct string, yet the Text Field is empty and never gets set.
yes, I checked the connections in IB.
Any ideas? thanks!
Found the answer.
I needed to initialize the NSXMLDocument with NSXMLDocumentTidyXML like:
NSXMLDocument* doc = [[NSXMLDocument alloc] initWithContentsOfURL: [NSURL fileURLWithPath:input] options:NSXMLDocumentTidyXML error:NULL];
You should print out DBLocationString instead of DBLoc to make sure it's not empty or in some corrupted format that can't be passed as a string value and go from there.

NSTextView add URL link to the selected Text?

I Have an NSTextView.
I just want to add an Attribute (an NSLinkAttributeName) to the selected Text in the NSTextView...
Can You Help me ?
Thanks.
You want to get the view's textStorage (which is basically a mutable attributed string), then add the NSLinkAttributeName attribute to the selected range; the value of that attribute is the URL to link to.
[[textView textStorage] addAttribute: NSLinkAttributeName value: url range:[textView selectedRange]];
Been a while since I played with ObjC but this should do the trick. It replaces the selected text with the original content with your attr appended. Checked through it but please excuse any typos.
NSTextView *textView = ...;
NSDictionary *attributes = ...;
//Get selected text string from TextView (see Text superclass) and append attr link
NSRange selRange = [textView selectedRange];
NSMutableString *changedStr = [[[textView string] substringWithRange:selRange] mutableCopy];
[changedStr appendString:[attributes objectForKey:NSLinkAttributeName]];
//Replace the selected text range in the TextView
[textView replaceCharactersInRange:selRange withString:[NSString stringWithString:changedStr]];
[changedStr release];
See class defs:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSText_Class/Reference/Reference.html
-replaceCharactersInRange:withString:
-selectedRange
-scrollRangeToVisible: if you want to present your change immediately
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html
substringWithRange:

Resources