2011-11-24 59 views
0
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ NSMutableString *message=[[NSMutableString alloc]init]; 
    // Notifies users about errors associated with the interface 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      message = @"Result: canceled"; 
      break; 
     case MFMailComposeResultSaved: 
      message = @"Result: saved"; 
      break; 
     case MFMailComposeResultSent: 
      message = @"Result: sent"; 
      break; 
     case MFMailComposeResultFailed: 
      message = @"Result: failed"; 
      break; 
     default: 
      message = @"Result: not sent"; 
      break; 
    } 

我使用mailcomposer的上述代码。编译时会给出警告incompatable pointer types assigning to NSMutableString from NSString。我相信这发生在我们使用NSString而不是NSMutableString时。我该如何解决这个问题? 在此先感谢。错误警告疑惑

回答

3

如果除了切换大小写外,您没有将任何内容附加到“消息”中,请使用NSString而不是NSMutableString。

如果你必须使用一个可变的字符串,而不是

message = @"Result: cancelled"; 

使用

[message appendString:@"Result: cancelled"]; 
+0

@lostln交通情况MFMailComposeResultCancelled: [消息appendString:@ “结果:取消”]; 休息;对??? – ICoder

+0

@编码器是的。我只是想发布与警告相关的代码。其他一切都保持不变。在每种情况下都会做出相同的更改([message appendString:])。 – lostInTransit

2

而不是分配新的价值,你必须要追加值一样,

[message appendString:@"Result: canceled"]; 

最后,你可以使用message

2

在这里,我可以看到潜在的内存泄漏的情况下......当你正在创建使用初始化NSMutableString对象,然后分配NSString对象。

所以,建议您使用NSMutableStringappendString方法。