0

我已将以下代码放入...;

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
@"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %@",field.text,     
kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

...我收到一个 NSException 错误说;

*** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate:     
<NSInvalidArgumentException> +[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil.  Or, did  
you forget to nil-terminate your parameter list?

这是什么意思?我该怎么做才能解决这个问题?

谢谢,

詹姆士

4

4 回答 4

4

您正在尝试在字典初始化中格式化字符串,并且它期望格式为object, key, object, key, etc... 要解决此问题,请尝试在另一行上创建格式化字符串以清楚起见,然后将其添加为对象和键的一部分

NSString *message = [NSString stringWithFormat:@"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %@",
                                                 field.text];
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:
                              @"text/plain", kSKPSMTPPartContentTypeKey,
                              message, kSKPSMTPPartMessageKey,
                              @"8bit", kSKPSMTPPartContentTransferEncodingKey,nil];
于 2011-09-08T19:57:55.840 回答
2

也许你的意思是这样的:

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain", kSKPSMTPPartContentTypeKey, [NSString stringWithFormat:@"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %@",field.text], kSKPSMTPPartMessageKey, @"8bit", kSKPSMTPPartContentTransferEncodingKey,nil];
于 2011-09-08T19:56:27.127 回答
1

你错过了一个论点。我计算了 8 个总论点,包括 nil。这意味着您的键值对之一不完整。

于 2011-09-08T19:55:15.390 回答
1

尝试首先创建字符串:

NSString *partMessageKey = [NSString stringWithFormat:@"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %@",field.text];

然后将此字符串作为对象放入字典。

于 2011-09-08T19:56:10.673 回答