0
嗨,大家好,我試圖從全局變量中取值,並將它們放入電子郵件中,我將包含我的源代碼和錯誤消息。提前致謝!沒有數據進入變量,請幫助嗎? iPhone iOS - Objective-C
MFMailComposeViewController *compose = [[MFMailComposeViewController alloc] init];
compose.mailComposeDelegate = self;
[compose setSubject:@"Float Plan for my Boat Trip"];
[compose setCcRecipients:[NSArray arrayWithObject:@"[email protected]"]];
NSString *emailFileName = [NSString stringWithFormat:@"email_en_US.html"];
NSString *emailFilePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: emailFileName];
NSString *body = [NSString stringWithContentsOfFile:emailFilePath encoding:NSUTF8StringEncoding error:nil];
body = [body stringByReplacingOccurrencesOfString:@"//PERSON//" withString:@"person"];
body = [body stringByReplacingOccurrencesOfString:@"//POB//" withString:pob];
body = [body stringByReplacingOccurrencesOfString:@"//PHONE//" withString:phone];
body = [body stringByReplacingOccurrencesOfString:@"//MEDICAL//" withString:medical];
body = [body stringByReplacingOccurrencesOfString:@"//DEPART//" withString:depart];
body = [body stringByReplacingOccurrencesOfString:@"//LEFT//" withString:left];
body = [body stringByReplacingOccurrencesOfString:@"//ARRIVAL//" withString:arrive];
body = [body stringByReplacingOccurrencesOfString:@"//DESTINATION//" withString:destination];
body = [body stringByReplacingOccurrencesOfString:@"//VESSELNAME//" withString:vessel_name];
body = [body stringByReplacingOccurrencesOfString:@"//BUILDERMAKE//" withString:builder_make];
body = [body stringByReplacingOccurrencesOfString:@"//LENGTH//" withString:length];
body = [body stringByReplacingOccurrencesOfString:@"//HULLCOLOUR//" withString:colour];
body = [body stringByReplacingOccurrencesOfString:@"//NUMBER//" withString:number];
body = [body stringByReplacingOccurrencesOfString:@"//POWER//" withString:power];
body = [body stringByReplacingOccurrencesOfString:@"//RIG//" withString:rig];
NSString *emailBody = body;
[compose setMessageBody:emailBody isHTML:YES];
compose.navigationBar.barStyle = UIBarStyleBlack;
[self presentModalViewController:compose animated:YES];
[compose release];
,這裏是,即時通訊在控制檯獲取錯誤,瞬間我按下電子郵件click事件
2011-02-28 18:26:34.595 Tow Boat 911[35121:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString stringByReplacingOccurrencesOfString:withString:options:range:]: nil argument'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f6abe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00d5f5c2 objc_exception_throw + 47
2 CoreFoundation 0x00f23628 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x00f2359a +[NSException raise:format:] + 58
4 Foundation 0x0004f3c0 -[NSString stringByReplacingOccurrencesOfString:withString:options:range:] + 123
5 Foundation 0x0004f33e -[NSString stringByReplacingOccurrencesOfString:withString:] + 99
6 Tow Boat 911 0x00001ec5 -[FloatPlan email:] + 477
7 UIKit 0x002b8a6e -[UIApplication sendAction:to:from:forEvent:] + 119
8 UIKit 0x003471b5 -[UIControl sendAction:to:forEvent:] + 67
9 UIKit 0x00349647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
10 UIKit 0x00348438 -[UIControl touchesBegan:withEvent:] + 277
11 UIKit 0x002dd025 -[UIWindow _sendTouchesForEvent:] + 395
12 UIKit 0x002be37a -[UIApplication sendEvent:] + 447
13 UIKit 0x002c3732 _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x01781a36 PurpleEventCallback + 1550
15 CoreFoundation 0x00f4c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x00eac6f7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x00ea9983 __CFRunLoopRun + 979
18 CoreFoundation 0x00ea9240 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00ea9161 CFRunLoopRunInMode + 97
20 GraphicsServices 0x01780268 GSEventRunModal + 217
21 GraphicsServices 0x0178032d GSEventRun + 115
22 UIKit 0x002c742e UIApplicationMain + 1160
23 Tow Boat 911 0x00001a8c main + 102
24 Tow Boat 911 0x00001a1d start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: 「SIGABRT」.
(gdb)
您可能會考慮使用'NSMutableString'並對就地字符串進行編輯,因爲'stringByReplacingOccurrencesOfString:withString:'每次調用時都會創建一個新的字符串對象。 – dreamlax 2011-03-01 00:22:39
你在哪裏定義你用作替換的字符串(pob,phone,medical,depart ...)?如果這些都是零,你可以得到上面的例外。 – 2011-03-01 01:28:13