-2

好的,在网上找到了几个教程。一切都很好,除非按下按钮。我按下将发送电子邮件的按钮,突然有一个信号中止。我观看了两个视频,并在每个视频中重新输入了每个代码两次。为什么会出现信号中断?请帮忙。谢谢!

这是.h文件

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface secondViewController : UIViewController <MFMailComposeViewControllerDelegate> {

    IBOutlet UILabel *resultLabel;
}
-(IBAction)switchToFirst:(id)sender;
-(IBAction)openMail:(id)sender;

@end

这是 .m 文件

#import "secondViewController.h"
#import "ViewController.h"

@interface secondViewController ()

@end

@implementation secondViewController


-(IBAction)openMail:(id)sender {

    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"", nil]];
        [composer setSubject:@""];
        [composer setMessageBody:@"message" isHTML:YES];
        [composer setModalTransitionStyle:UIModalTransitionStylePartialCurl];
        [self presentModalViewController:composer animated:YES];
    }
    else {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Can't send your email!" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
        [alert show];

    }

}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    switch (result) {
        case MFMailComposeResultSent:
            resultLabel.text = @"Mail was sent";
            break;

        case MFMailComposeResultSaved:
            resultLabel.text = @"Mail was saved to drafts";
            break;

        case MFMailComposeResultFailed:
            resultLabel.text = @"Mail wasn't able to sent";
            break;

        case MFMailComposeResultCancelled:
            resultLabel.text = @"Mail was Cancelled";
            break;


    }

    [self dismissModalViewControllerAnimated:YES];
}


-(IBAction)switchToFirst:(id)sender {
    ViewController *second = [[ViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:second animated:YES];

}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    // Set the background image by setting the contents of the view's layer
    UIImage *bg = [UIImage imageNamed:@"iPad iDeaf Assisstant Background.png"];
    self.view.layer.contents = (id) [bg CGImage];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
4

2 回答 2

0

如果你有一个用于发送电子邮件的类,你可以在没有 arc 的情况下编译它,只需在项目设置 -> 构建阶段为文件设置标志-fno-objc-arc

于 2012-07-31T18:45:07.767 回答
0

就像@qegal 说的那样,把所有的retainsreleases.

如果你想保留你拥有的代码,你可以将文件标记为非弧。

要将任何文件标记为非弧,您可以在构建阶段设置编译器标志。在左侧的文件窗格中选择您的项目。然后选择您的目标,进入构建阶段,双击您要标记的文件的编译器标志下方的列,然后输入“fno-objc-arc”。

于 2012-07-31T19:10:19.513 回答