1

After several attempts I do not succeed to understand were is the error and why the image doesn't appear... This is my code.

myProtocol.h

#import <Foundation/Foundation.h>

@protocol myProtocol <NSObject>

-(UIImage *)transferImage;

@end

ViewController.h

#import "SecondViewController.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:@"VoodooVibeThumb@2x.png"]];
    [view addSubview:_imageView];
    NSLog(@"VoodooVibeThumb@2x.png");
}

-(UIImage *)transferImage
{
    NSLog(@"VoodooVibeThumb@2x.png"); 
    return _imageView.image;
} 

- (IBAction)sendImage:(id)sender 
{    
    SecondViewController *secClass = [[SecondViewController alloc] init];
    [secClass setImageName:@"VoodooVibeThumb@2x.png"];
    [self.navigationController pushViewController:secClass animated:YES];
}

- (void)didReceiveMemoryWarning 
{
    [super didReceiveMemoryWarning];
} 

@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,retain) UIImageView *myImage;
@property (nonatomic,retain) UIImage *transferImage;
@property(nonatomic,assign) id delegate;
@property (strong, nonatomic)NSString *imageName;

-(void)callTransfer;

@end

SecondViewController.m

#import "SecondViewController.h"
#import "ViewController.h"
#import "myProtocol.h" 

@interface SecondViewController ()
@end 

@implementation SecondViewController

@synthesize delegate, myImage, transferImage;

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

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[myImage setImage:[UIImage imageNamed:_imageName]];
UIImageView * myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:_imageName]];
[secondView addSubview:myImage];
}

-(void)callTransfer
{
    myImage.image=[delegate performSelector:@selector(transferImage)];
    myImage.image=[UIImage imageNamed:@"VoodooVibeThumb@2x.png"];
    NSLog(@"%@",myImage.image);
    NSLog(@"I am in call transfer");
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
4

3 に答える 3

1

これを使って:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    myImage = [[UIImageView alloc] initWithImage[UIImage imageNamed:_imageName]];
    [secondView addSubview:myImage];
}

インターフェイス (.h または .m のいずれか) に myImage という変数があると思います。そのため、myImage のローカル インスタンス (UIImageView *myImage) を作成すると、XCode が混乱します。最新と宣言されているため (参照なし、申し訳ありません)、ローカル宣言を使用していますが、アクセスできない同じ名前を使用するインスタンス変数があることを認識しています。UIImageView *代わりに、メソッドからを削除して、インスタンス変数に直接保存したい

これが理にかなっていることを願っています!

マット

于 2013-10-18T15:42:22.863 に答える
0

[secondView addSubview:myImage];

エラー: 'myImage' hidesistance 変数のローカル宣言。

ここに画像の説明を入力

于 2013-10-18T15:31:58.690 に答える