0

ViewController.m will assemble the body of an email as the user pushes buttons and types in textviews. The program that reads the email asks that it is in XML. The final message will look like this:

NSString *sendMessage = [[NSString alloc]initWithFormat:@"<?xml version = \"1.0\" ?>\n<?commitcrmxml version = \"1.0\" ?>\n<CommitCRMTransaction>\n<ExternalApplicationName>Myapp</ExternalApplicationName>\n<SendResponseToEmail>err@mysite.com</SendResponseToEmail>\n<Password>pass</Password>\n<ReturnTransactionID>CRDOWV34HL53J543GENDYDH92BSF</ReturnTransactionID>\n<DataKind>TICKET</DataKind>\n<RecordData>\n<FLDTKTCARDID>%@</FLDTKTCARDID>\n<FLDTKTPROBLEM>%@\n%@\n%@\n%@\n%@\n%@</FLDTKTPROBLEM>\n<FLDTKTSTATUS>100</FLDTKTSTATUS>\n<FLDTKTKIND>General</FLDTKTKIND>\n<FLDTKTPRIORITY>10</FLDTKTPRIORITY>\n<FLDTKTSOURCE>Myapp</FLDTKTSOURCE>\n<FLDTKTSCHEDLENESTIM>60</FLDTKTSCHEDLENESTIM>\n<FLDTKTFORDISPATCH>N</FLDTKTFORDISPATCH>\n</RecordData>\n</CommitCRMTransaction>", cardID, tempStoreCompany, tempStoreLocation, tempStoreName, tempStorePhone, tempStoreEmail, descriptionMessage];

My second implementation file, MailSend.m, Is going to send the message using (SKP)SMTP. MailSend.m needs access to the text in the sendMessage string (in ViewController.m) so that the message may be sent properly.

How can I do this?

2 Answers2

0

Make a property

@property (nonatomic,retain) NSString *sendText;

in .h file and synthesize in .m file as

@synthesize sendText;

Then set it where you are allocating your MailSend object like

MailSend *ms = [[MailSend alloc] init....];
ms.sendText = sendMessage;
[self present...];
//or self.navigationController pushVie...];

and access this string using sendText in MailSend.m

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
0

There are three simple ways that you can go about doing this.


The first is how Inder stated in which you create a property and set it.


The second way would be to create a method that accepts a NSString as s parameter in your SecondViewController.

SecondViewController.h

- (void)setTextBody:(NSString*)_body;

SecondViewController.m

- (void)setTextBody:(NSString*)_body {
localBodyString = _body;
}

FirstViewController.m

SecondViewController *second = [[SecondViewController alloc] init...];
[second setTextBody:sendMessage];
//Push the view controller

Another way to do this would be to add a new init method to the SecondViewController class that accepts a NSString.

SecondViewController.h

- (id)initWithString:(NSString*)_body;

SecondViewController.m

- (id)initWithString:(NSString*)_body {
if (self)
 localBodyString = _body;
return self;
}

FirstViewController.m

SecondViewController *second = [[SecondViewController alloc] initWithString:sendMessage];
//Push view controller

Now if both of these you will need to define a NSString *localBodyString variable in the header file.

random
  • 8,568
  • 12
  • 50
  • 85