オンラインでいくつかのチュートリアルを見つけたらOKです。ボタンを押している時以外は問題ありません。電子メールを送信するボタンを押したところ、突然中断信号が発生しました。2 つのビデオを見て、各ビデオのすべてのコードを 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