2017-01-31 6 views
0

뷰 계층 구조에 어려움을 겪고 있지만 여기서 어떤 문제가 있는지 알 수 없습니다. 메시지 (MFMessageComposeViewController)를 보내려고합니다. 위임 메서드를 사용하여 성공 여부에 따라 alertView을 표시하고 싶습니다. 완료 블록이 MFMessageComposeView 전에 호출 된 것처럼 completey 때 메시지 기각 (또는 할당 취소) 것처럼MFMessageController를 해제 할 때 AlertView를 표시 할 때 오류가 발생합니다.

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x153b3c00>) 

것 같습니다 다음 alertView는 메시지가 취소 될 때 표시하지만 메시지가 전송이 오류를 얻을 수있다 (장면 뒤에서 뭔가 움직이는 것처럼) 보내지 만 취소되지는 않습니다. 가 도움이 될 수있는 경우 :

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { 

    int tag; 

    switch (result) { 
     case MessageComposeResultCancelled: 
     { 
      tag = 1; 
      NSLog(@"Cancelled"); 
      break; 
     } 
     case MessageComposeResultFailed: 
     { 
      tag = 2; 
      NSLog(@"Failed"); 
      break; 
     } 

     case MessageComposeResultSent: 
     { 
      tag = 3; 
      NSLog(@"Sent"); 
      break; 
     } 
     default: 
      break; 
    } 
    [controller dismissViewControllerAnimated:YES completion:^{ 
     [self alertSMSMessageWithTag:tag]; 
    }]; 
} 

- (void)alertSMSMessageWithTag:(int)tag { 

    UIAlertController *alertController; 

    if (tag == 1) { // cancelled 
     alertController = [UIAlertController alertControllerWithTitle:@"Message cancelled" message:nil preferredStyle:UIAlertControllerStyleAlert]; 
     UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
     [alertController addAction:ok]; 
    } 
    if (tag == 2) { // Failed 
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Message failed" message:nil preferredStyle:UIAlertControllerStyleAlert]; 
     UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
     [alertController addAction:ok]; 
    } 
    if (tag == 3) { // sent 
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Message sent" message:nil preferredStyle:UIAlertControllerStyleAlert]; 
     UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
     [alertController addAction:ok]; 
    } 
    [self presentViewController:alertController animated:YES completion:nil]; 
} 

누군가가 나를 도울 수 있다면

... 당신은 적절한 방법으로 UIAlertController을 초기화하는 없습니다

답변

0

. 당신은

if (tag == 3) { 
} 

하지만 방법에 공개하지 않도록 공개 같은 변수 이름 alertController을 사용하고 있습니다. 그리고 당신은 내가 다음 코드를 사용하도록 제안 올바르게 태그 1. 초기화 한 UIAlertController *alertController; [self presentViewController:alertController animated:YES completion:nil];UIAlertController *alertController; 즉 방법 변수에 공공 액세스하는 방법을 공개 같은 변수 이름을 사용하는 -

- (void)alertSMSMessageWithTag:(int)tag { 

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert]; 
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
    [alertController addAction:ok]; 
    if (tag == 1) { // cancelled 
     alertController.title = @"Message cancelled"; 

    } 
    if (tag == 2) { // Failed 
     alertController.title = @"Message failed"; 
    } 
    if (tag == 3) { // sent 
     alertController.title = @"Message sent"; 

    } 
    [self presentViewController:alertController animated:YES completion:nil]; 
} 

는 희망을 그 도움이됩니다.