2011-11-24 86 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方法。