2017-04-27 45 views
0

我有一個單例,並且在其中創建了一個將由多個viewcontrollers使用的自定義方法。該方法是顯示一個電子郵件作曲家。無法在全局方法中分配委託

-(void)emailSend:(NSString*)bodyStr inVC:(UIViewController*)vc { 

    if ([MFMailComposeViewController canSendMail]) { 

     NSString *messageBody = bodyStr; 
     MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; 
     mc.mailComposeDelegate = vc; // <-- warning 
     [mc setSubject:@"Say Hello"]; 
     [vc presentViewController:mc animated:YES completion:NULL]; 
    }else{ 

     // Not setup 
    } 

} 

在其他viewcontrollers我被稱之爲:

[[MySingle singleton] emailSend:@"Testing" inVc:self]; 

警告消息是由不兼容的 類型的UIViewController * __強

任何分配給

ID __Nullable如何使其工作?

+0

嗨親愛的,可以ÿ ou試試這個:__weak typeof(self)weakSelf = self; [[MySingle singleton] emailSend:@「Testing」inVc:weakSelf]; ** OR **用類名取代自己 – ajjjjjjjj

+0

您需要將代理添加到您的VC class MyVC: SeanLintern88

+1

更改爲:** nVC:(id)vc **。 – KKRocks

回答

1

你需要讓你的方法的一些變化:

來源:

- (空)emailSend:(的NSString *)bodyStr INVC:(UIViewController的*)VC

要:

- (空)emailSend:(的NSString *)bodyStr INVC:(ID)VC