0

我的项目出现错误,我收到 Xcode 错误实例方法 -addAttachment withImageNamed not found,下面是我的一些代码:

HegakaDragAndDropRecycleBinViewController.h

@interface HegakaDragAndDropRecycleBinViewController : UIViewController {
IBOutlet GalleryScrollView *gallery;

}
-(NSString*)withImageNamed;

@property (nonatomic, retain) IBOutlet GalleryScrollView *gallery;
@end

HegakaDragAndDropRecycleBinViewController.m

#import "HegakaDragAndDropRecycleBinViewController.h"
#import "AttachmentItem.h"

@implementation HegakaDragAndDropRecycleBinViewController

@synthesize gallery;

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

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
 {
[super viewDidLoad];
self.gallery.mainView = self.view;


AttachmentItem *item = [[AttachmentItem alloc] initWithData:1 data:nil];
[self.gallery addAttachment:item withImageNamed:@"recyclebin"];
[self.gallery addAttachment:item withImageNamed:@"canadian-maple"];
[self.gallery addAttachment:item withImageNamed:@"light-cherry"];
[self.gallery addAttachment:item withImageNamed:@"mozambique-wenge"];
[self.gallery addAttachment:item withImageNamed:@"canadian-maple"];

[item release];
}

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

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

我在实施行和此处收到警报警告:

[self.gallery addAttachment:item withImageNamed:@"recyclebin"];
[self.gallery addAttachment:item withImageNamed:@"canadian-maple"];
[self.gallery addAttachment:item withImageNamed:@"light-cherry"];
[self.gallery addAttachment:item withImageNamed:@"mozambique-wenge"];
[self.gallery addAttachment:item withImageNamed:@"canadian-maple"];

该项目仍在运行,但有这 6 个警告。

非常感谢任何帮助。

谢谢

4

2 回答 2

1

Make sure your class AttachmentItem declares addAttachment:withImageNamed: in its header file

于 2012-11-12T08:33:20.690 回答
0

首先:

  • 警告说什么?

What I think is happening is that you should import the GalleryScrollView in your .m file. Since you are trying to use a method from that specific class, I guess Xcode, is not able to see that it has -addAttachment:withImageNamed:. That's why it runs ok (the method exists in fact), but gives a warning because from a HegakaDragAndDropRecycleBinViewController you can't see it. Also, you should treat warnings as errors. This can help you solving nasty things that can happen latter in development.

于 2012-11-12T08:30:29.253 回答