MFMessageComposeController问题

时间:2012-03-21 17:18:35

标签: iphone xcode ios5 mfmailcomposeviewcontroller

我的MFMessageComposeController出了问题。因此,在我的应用程序中,每次单击按钮时,都会出现UIActionSheet,然后您必须选择是否要拨打电话或发送消息。但每次我打电话,结束它并返回我的应用程序,我的MFMessageComposeController出现......问题出在哪里?这是代码,如果有帮助

case 0 : {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"tel://011212"]];
    [actionSheet dismissWithClickedButtonIndex:0 animated:NO];            
}
case 1: {
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];   
}





[[UIApplication sharedApplication ] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
MFMessageComposeViewController*controller =[[[MFMessageComposeViewController alloc] init] autorelease];

if ([MFMessageComposeViewController canSendText]) {

    controller.body = [NSString stringWithFormat:@"Narucio bih Oryx Taxi na lokaciju ( %@ , %@ ) .\nNaruci! aplikacija", latitudePoint.text, longitudePoint.text];



    controller.recipients = [NSArray arrayWithObjects:@"011888",nil];
    //controller.messageComposeDelegate = self;
    controller.messageComposeDelegate=self;
    controller.navigationBar.tintColor = [UIColor grayColor];

    [self presentModalViewController:controller animated:YES];

3 个答案:

答案 0 :(得分:1)

您需要在switch语句中的每个案例后添加一个中断。否则执行将落到下一个案例。

case 0 : {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"tel://011212"]];
    [actionSheet dismissWithClickedButtonIndex:0 animated:NO];  
    break;          
}
case 1: {
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];  
    break; 
}

答案 1 :(得分:0)

你还没有结束switch语句case 0,所以即使它执行第一种情况,它也总是进入第二种情况。解决方案是使用break

case 0 : {
  [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"tel://011212"]];
  [actionSheet dismissWithClickedButtonIndex:0 animated:NO];  
  break;          
}
case 1: {
  [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];  
  break; 
}

答案 2 :(得分:0)

您需要在每个案例完成后放置break;,以确保不会执行当前案例之后的案例。

试试这段代码:

case 0 : {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"tel://011212"]];
    [actionSheet dismissWithClickedButtonIndex:0 animated:NO]; 
    break;
}
case 1: {
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];
    break;   
}
default:
    break;


    MFMessageComposeViewController*controller =[[[MFMessageComposeViewController alloc] init] autorelease];

    if ([MFMessageComposeViewController canSendText]) {

        controller.body = [NSString stringWithFormat:@"Narucio bih Oryx Taxi na lokaciju ( %@ , %@ ) .\nNaruci! aplikacija", latitudePoint.text, longitudePoint.text];



        controller.recipients = [NSArray arrayWithObjects:@"011888",nil];
        //controller.messageComposeDelegate = self;
        controller.messageComposeDelegate=self;
        controller.navigationBar.tintColor = [UIColor grayColor];

        [self presentModalViewController:controller animated:YES];
    }

希望这会对你有所帮助。