Cocos2d:关闭邮件编辑器视图后应用程序崩溃

时间:2012-12-15 08:16:45

标签: iphone ios cocos2d-iphone

在我的应用程序中我有7个按钮我在该视图中显示3个按钮后按下箭头显示其他3个按钮

1.Facebook分享 2.twitter份额 3.告诉朋友 4.report 5.starter指南 6.访问我的网站 7.反馈

     LIKE THIS MY VIEW
    ====================
          ^        ---->up arrow

      facebook share

      Twitter share

      Tell a friend

           V      ---->down arrow

我使用mailcomposerview“告诉朋友”按钮和“报告”按钮

当我按下“告诉朋友”或“报告”按钮时,它会在关闭后打开mailcomposerview,我无法移动向上和向下箭头......如果我按向上和向下箭头则打开同样的邮件composerview,它也没有打开Facebook分享和推特分享

请帮我解决这个问题

按下箭头时

我的编码

 -(void)arrTapped1:(id)sender
 {
CCMenuItem *item2=(CCMenuItem*)sender;
int k=item2.tag;
    ////CCLOG(@"k tapp=%dhelp=%d",k,helpVal);

    NSLog(@"HelpVal%i",helpVal);
if(k==51)
{
    if(helpVal<3)
    { 
        id action1=[CCMoveBy actionWithDuration:0.3 position:ccp(0,+260)];
        id callfun1=[CCCallFunc actionWithTarget:self selector:@selector(enabled1) ]; 

        [item2 setIsEnabled:YES];
        [(CCSprite*)[self getChildByTag:10] runAction:[CCSequence actions:action1,callfun1,nil]];
        [self performSelector:@selector(downWardsMove)];
            }

}
else //if(k==50)
        {
    if(helpVal>1)
    {  

        id action1=[CCMoveBy actionWithDuration:0.3 position:ccp(0,-260)];
        id callfun1=[CCCallFunc actionWithTarget:self selector:@selector(enabled1) ]; 
        [item2 setIsEnabled:YES];

        [(CCSprite*)[self getChildByTag:10] runAction:[CCSequence actions:action1,callfun1,nil]];
        [self performSelector:@selector(upWardsMove)];
    }   } }

    //code for upwards & downwards move
    //--------------------------------

  -(void)upWardsMove
   {
      [upArrItem setIsEnabled:NO];
  [downArrItem setIsEnabled:NO];
  self.isTouchEnabled=NO;
  helpVal--;
  [(CCMenu*)[self getChildByTag:53] setVisible:YES];
  [downArrItem setIsEnabled:YES];
      if(helpVal==1)
  {
    [(CCMenu*)[self getChildByTag:52] setVisible:NO];
    [upArrItem setIsEnabled:NO];
  } 
   }


-(void)downWardsMove
 {
    [upArrItem setIsEnabled:NO];
[downArrItem setIsEnabled:NO];
self.isTouchEnabled=NO;
    helpVal++;
    [(CCMenu*)[self getChildByTag:52] setVisible:YES];
[upArrItem setIsEnabled:YES];
if(helpVal==3){
    [(CCMenu*)[self getChildByTag:53] setVisible:NO];
    [downArrItem setIsEnabled:NO];
}
}
 -(void)enabled1
  {
self.isTouchEnabled=YES;
[upArrItem setIsEnabled:YES];
[downArrItem setIsEnabled:YES];
if(helpVal==3)
{
    [(CCMenu*)[self getChildByTag:53] setVisible:NO];
    [downArrItem setIsEnabled:NO];
}
if(helpVal==1)
{
    [(CCMenu*)[self getChildByTag:52] setVisible:NO];
    [upArrItem setIsEnabled:NO];
}
   }

 //sending mail code
//------------------

-(void)sendMail
{
  mailComposer = [[UIViewController alloc] init];
  [[[CCDirector sharedDirector] openGLView] addSubview:mailComposer.view];
  MFMailComposeViewController *mailController= [[MFMailComposeViewController alloc] init];                
  mailController.mailComposeDelegate = self;    
  [mailController setSubject:msgSubject];
  [mailController setMessageBody:mailContent isHTML:YES];
  NSArray *toRecipients = [NSArray arrayWithObject:@"Info@ask.com"];
  [mailController setBccRecipients:toRecipients];
  [mailComposer presentModalViewController:mailController animated:NO];
  mailComposer.view.transform = CGAffineTransformMakeRotation( CC_DEGREES_TO_RADIANS(90.0f ) );
  [mailController release];
  [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight]     
  }

 -(void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult: (MFMailComposeResult)result  error:(NSError*)error
 {
    [mailComposer dismissModalViewControllerAnimated:YES];
 }

2 个答案:

答案 0 :(得分:0)

以下是我在我的应用中使用的代码的一部分,它在iOS 4.0 - iOS 6.0中运行良好。看看:

-(void)sendMessageToEmail:(NSString *)message withSubject:(NSString *)subject
{
    if([self _isIOS6andHigher]) {

        NSArray *activities = @[message];
        UIActivityViewController *viewController = [[UIActivityViewController alloc] initWithActivityItems:activities applicationActivities:nil];

        AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
        [[app navController] presentViewController:viewController animated:YES completion:nil];
        [viewController release];

    } else {

        MFMailComposeViewController* mailController = [[MFMailComposeViewController alloc] init];
        mailController.mailComposeDelegate = self;
        [mailController setSubject:subject];
        [mailController setMessageBody:message isHTML:NO];

        AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
        [[app navController] presentModalViewController:mailController animated:YES];
        [mailController release];
    }
}

- (void)mailComposeController:(MFMailComposeViewController*)controller
      didFinishWithResult:(MFMailComposeResult)result
                    error:(NSError*)error
{
    [controller dismissModalViewControllerAnimated:YES];

}

答案 1 :(得分:0)

您永远不会发布mailComposer:

mailComposer = [[UIViewController alloc] init];

这可能会导致它泄漏并作为视图保持活动状态。这可以解释缺少触摸事件,因为邮件编辑可能仍会拦截触摸。