iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – 从不兼容的类型’MainViewController *’分配给’id’大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我的代码中有以下警告(XCode 4.3 / iOS 4/5) – 从不兼容的类型’MainViewController *’分配’id’ 本节提出警告 – - (IBACtion)sendInAppSMS:(id)sender { MFmessageComposeViewController *controller = [[[MFmessageComposeViewController allo
我的代码中有以下警告(XCode 4.3 / iOS 4/5) –

从不兼容的类型’MainViewController *’分配’id’

本节提出警告 –

- (IBACtion)sendInAppSMS:(id)sender
{
MFmessageComposeViewController *controller = [[[MFmessageComposeViewController alloc] init] autorelease];
if([MFmessageComposeViewController canSendText])
{
    controller.body = @"A test message from http://www.macoscoders.com";
    controller.recipients = [NSArray arrayWithObjects:@"9880182343",nil];
    controller.messageComposeDelegate = self;
    [self presentModalViewController:controller animated:YES];
}
}

特别是这条线 –

controller.messageComposeDelegate = self;

有点困惑我的代码有什么问题.谷歌搜索警告我发现了一些参,但我很难理解答案.

任何指针/解释将不胜感激.

最好的祝福

我完整的.h文件

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolBox/AudioToolBox.h>
#import <messageUI/messageUI.h>
#import "EasyTracker.h"

@interface MainViewController : TrackedUIViewController <MFMailComposeViewControllerDelegate> {

IBOutlet UIView *volumeSlider;  
AVPlayer *radiosound;

IBOutlet UIButton *playpausebutton;

IBOutlet UIActivityInDicatorView *activityInDicator;
NSTimer *timer;

}

@property(nonatomic,retain) AVPlayer                   *radiosound;
@property(nonatomic,retain) UIButton                   *playpausebutton;

- (void)updatebuttonstatus;

- (void)playCurrentTrack;
- (void)pauseCurrentTrack;
- (IBACtion)playbutton;
- (IBACtion)openMail:(id)sender;
- (IBACtion)sendInAppSMS:(id)sender;

@end

我的.m文件的亮点 –

#import "MainViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AudioToolBox/AudioToolBox.h>
#import <MediaPlayer/MediaPlayer.h>
#import "radio99AppDelegate.h"

@implementation MainViewController



- (IBACtion)sendInAppSMS:(id)sender
{
MFmessageComposeViewController *controller = [[[MFmessageComposeViewController alloc] init] autorelease];
if([MFmessageComposeViewController canSendText])
{
    controller.body = @"A test message from http://www.macoscoders.com";
    controller.recipients = [NSArray arrayWithObjects:@"9880182343",nil];
    controller.messageComposeDelegate = self;
    [self presentModalViewController:controller animated:YES];
}
}

- (void)messageComposeViewController:(MFmessageComposeViewController *)controller didFinishWithResult:(messageComposeResult)result
{
switch (result) {
    case messageComposeResultCancelled:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithtitle:@"SMSTester" message:@"User cancelled sending the SMS"
                                                      delegate:self cancelButtontitle:@"OK" otherButtontitles: nil];
        [alert show];
        [alert release];
    }
        break;
    case messageComposeResultFailed:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithtitle:@"SMSTester" message:@"Error occured while sending the SMS"
                                                       delegate:self cancelButtontitle:@"OK" otherButtontitles: nil];
        [alert show];
        [alert release];
    }
        break;
    case messageComposeResultSent:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithtitle:@"SMSTester" message:@"SMS sent successfully..!"
                                                       delegate:self cancelButtontitle:@"OK" otherButtontitles: nil];
        [alert show];
        [alert release];
    }
        break;
    default:
        break;
}

[self dismissModalViewControllerAnimated:YES];
}

- (IBACtion)openMail:(id)sender 
{
if ([MFMailComposeViewController canSendMail])
{
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

    mailer.mailComposeDelegate = self;

    [mailer setSubject:@"A message from MobileTuts+"];

    NSArray *toRecipients = [NSArray arrayWithObjects:@"fisrtMail@example.com",@"secondMail@example.com",nil];
    [mailer setToRecipients:toRecipients];

    UIImage *myImage = [UIImage imagenamed:@"mobiletuts-logo.png"];
    NSData *imageData = UIImagePNGRepresentation(myImagE);
    [mailer addAttachmentData:imageData mimeType:@"image/png" filename:@"mobiletutsImage"]; 

    NSString *emailBody = @"Have you seen the MobileTuts+ web site?";
    [mailer setmessageBody:emailBody isHTML:NO];

    [self presentModalViewController:mailer animated:YES];

    [mailer release];
}
else
{
    UIAlertView *alert = [[UIAlertView alloc] initWithtitle:@"Failure" 
                                                    message:@"Your device doesn't support the composer sheet" 
                                                   delegate:nil 
                                          cancelButtontitle:@"OK" 
                                          otherButtontitles: nil];
    [alert show];
    [alert release];
}

}

#pragma mark - MFMailComposeController delegate

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
switch (result)
{
    case MFMailComposeResultCancelled:
        NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"Mail saved: you saved the email message in the Drafts folder");
        break;
    case MFMailComposeResultSent:
        NSLog(@"Mail send: the email message is queued in the outBox. it is ready to send the next time the user connects to email");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Mail Failed: the email message was nog saved or queued,possibly due to an error");
        break;
    default:
        NSLog(@"Mail not sent");
        break;
}

[self dismissModalViewControllerAnimated:YES];
}

@end
@H_607_51@解决方法
您正在使用:

@H_4_25@mFMailComposeViewControllerDelegate

它应该在哪里:

@H_4_25@mFmessageComposeViewControllerDelegate

在这里改变:

@interface MainViewController : TrackedUIViewController <MFmessageComposeViewControllerDelegate> {

大佬总结

以上是大佬教程为你收集整理的iphone – 从不兼容的类型’MainViewController *’分配给’id’全部内容,希望文章能够帮你解决iphone – 从不兼容的类型’MainViewController *’分配给’id’所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。