2012-07-16 40 views
0

ViewController.m將在用戶按文本瀏覽中的按鈕和類型時組裝電子郵件的正文。讀取電子郵件的程序會要求它使用XML。最後的消息將是這樣的:iphone將字符串傳遞給項目中的另一個.m文件

NSString *sendMessage = [[NSString alloc]initWithFormat:@"<?xml version = \"1.0\" ?>\n<?commitcrmxml version = \"1.0\" ?>\n<CommitCRMTransaction>\n<ExternalApplicationName>Myapp</ExternalApplicationName>\n<SendResponseToEmail>[email protected]</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]; 

我的第二個實現文件,MailSend.m,會使用(SKP)SMTP發送郵件。 MailSend.m需要訪問sendMessage字符串中的文本(在ViewController.m中),以便可以正確發送消息。

我該怎麼做?

回答

0

使屬性

@property (nonatomic,retain) NSString *sendText; 

中的.h文件和.m文件合成爲

@synthesize sendText; 

然後設置它,你就像

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

分配好自己的MailSend對象並使用sendText訪問此字符串MailSend.m

0

有三種簡單的方法可以執行此操作。


第一個是Inder如何陳述您創建屬性並設置它。


第二種方法是創建一個方法,在SecondViewController中接受NSString作爲s參數。

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 

另一種方式做,這將增加一個新的init方法到SecondViewC接受NSString的ontroller類。

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 

現在,如果這兩個,你需要在定義的NSString * localBodyString變量頭文件。

+0

localBodyString是做什麼的? – user1489433 2012-07-16 18:06:32

+0

你可以隨心所欲地做任何事情。它是從FirstViewController分配的NSString。你可以設置一個UILabel來顯示它或任何。 – random 2012-07-23 20:11:29

相關問題