2

「プロトコル内のメソッドが実装されていません」というエラーが表示されてわかりません

myProtocol.h

#import <Foundation/Foundation.h>

@protocol myProtocol <NSObject>

-(UIImage *)transferImage;

@end

ViewController.h

#import "SecondClass.h"

@interface ViewController : UIViewController<myProtocol, UINavigationControllerDelegate>

{
UIView *view;

}

@property (nonatomic,retain) UIImageView *imageView;

- (IBAction)sendImage:(id)sender;

@end

ViewController.m

#import "ViewController.h"
#import "SecondViewController.h"
#import "myProtocol.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];

_imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"VoodooVibe@2x.png"]];

[view addSubview:_imageView];

NSLog(@"I am in VC.m");
}

-(UIImage *)transferImage{
NSLog(@"I am in transferImage");
return _imageView.image;}
- (IBAction)sendImage:(id)sender {
SecondViewController *secClass = [[SecondViewController alloc]init];

secClass.delegate=self;[secClass callTransfer];NSLog(@"送信者にいます");[self.navigationController pushViewController:secClass animation:YES];}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end

SecondViewController.h

#import <UIKit/UIKit.h>

#import "myProtocol.h"

#import "ViewController.h"

@interface SecondViewController :               UIViewController<myProtocol,UINavigationControllerDelegate> {

UIView *secondView;

IBOutlet UIImageView *myImage;

id <myProtocol> myDelegate;
}

@property (nonatomic,strong) UIImageView *myImage;

@property(nonatomic,weak) id delegate;

-(void)callTransfer;

@end

SecondViewController.m

#import "SecondViewController.h"

#import "ViewController.h"

#import "myProtocol.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

@synthesize delegate,myImage;

- (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.

[secondView addSubview:myImage];
}
-(void)callTransfer

{
myImage.image=[delegate performSelector:@selector(transferImage)];

myImage.image=[UIImage imageNamed:@"VoodooVibe@2x.png"];

NSLog(@"%@",myImage.image);

NSLog(@"I am in call transfer");

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
4

2 に答える 2

5

delegate内でメソッドを呼び出しSecondViewControllerますが、挿入しませんでした。このような警告が表示... not implementedされた場合は、メソッドを含めるのを忘れています。このようにメソッドを挿入できます

-(UIImage *)transferImage{
    //do something here if delegate has been called
}

delegateまたは、ブロック内のメソッドの上にパラメーターを追加するだけです。

@optional

指定しない場合、すべてのメソッドが@required初期に設定されます。

于 2013-10-13T16:14:50.580 に答える