iphone - Xcode错误语义错误值可能无法响应 'initWithFrame:image Name:'

标签 iphone objective-c xcode ios5 compiler-errors

我的项目出现错误。我尝试了很多解决方案,但无济于事。

我收到错误Xcode错误语义错误值可能无法响应'initWithFrame:image name:'

我不知道这意味着什么,为什么我得到这个警告。请帮忙。

谢谢

Link到我的项目,以及更新后的项目link

我在这行中得到错误

GalleryButton *btnAttachment = [[GalleryButton alloc] initWithFrame:CGRectMake(startX, startY, width, height) imageName:imgName];

GalleryScrollView.h
#import <UIKit/UIKit.h>
#import "AttachmentItem.h"
#import "GalleryButton.h"

@protocol GAlleryScrollDelegate;

@interface GalleryScrollView : UIView <GalleryButtonDelegate>

{

id <GAlleryScrollDelegate> delegate;

// MAIN WINDOW WHERE YOU CAN DRAG ICONS
UIView *mainView;

UIScrollView *_scrollView;
NSMutableArray *_attachments;


NSInteger *_totalSize;

UIImageView *_recycleBin;
CGRect recycleBinFrame;
}
@property (nonatomic, retain) id <GAlleryScrollDelegate> delegate;
@property (nonatomic, retain) UIView *mainView;
@property (nonatomic, retain) NSMutableArray *attachments;
@property (nonatomic, retain) UIImageView *recycleBin;
@property (nonatomic, retain) UIImageView *imgName;
@property (nonatomic) CGRect recycleBinFrame;

- (void) addAttachment:(AttachmentItem *)attachment withImageNamed:(NSString *)imgName;
- (void) removeAttachment:(GalleryButton *)button;
- (void) reloadData;
- (id) initWithFrame:(CGRect)frame imageName:(NSString *)imageName;

@end

// EVENTS IF YOU WANT TO DISABLE SOME SCROLL ON DID PRESS AND ENABLE IT ON DROP
@protocol GAlleryScrollDelegate
- (void) didPressButton;
- (void) didDropButton;
@end

GalleryScrollView.m
#import <QuartzCore/QuartzCore.h>
#import "GalleryScrollView.h"
#import "GalleryButton.h"

@implementation GalleryScrollView

@synthesize delegate;
@synthesize mainView;
@synthesize attachments = _attachments;
@synthesize recycleBin = _recycleBin, recycleBinFrame;

int padding = 0;

#pragma mark - INIT

- (id) init
{
self = [super init];
if (self) {
    // Initialization code here.
}
return self;
}

- (id) initWithFrame:(CGRect)frame imageName:(NSString *)imageName
{
self = [super initWithFrame:frame];
if (self){
    ;
}
return self;
}
- (void) awakeFromNib
{
// INIT ATTACHMENT ARRAY
if (_attachments == nil){
    _attachments = [[NSMutableArray alloc] init];
}

// SCROLL VIEW
UIScrollView *scrollTemp = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width-0, 450)];
_scrollView = scrollTemp;
_scrollView.backgroundColor = [UIColor clearColor];

// RECYCLE BIN
UIImageView *imageViewTemp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mozambique-wenge.png"]];
self.recycleBin = imageViewTemp;
self.recycleBin.frame = CGRectMake(0, 0, 320, 270);

[self addSubview:_scrollView];
[self addSubview:self.recycleBin];
[scrollTemp release];
[imageViewTemp release];
 }

- (void) dealloc {
[super dealloc];

}

#pragma mark - ATTACHMENTS ADD / REMOVE

- (void) addAttachment:(AttachmentItem *)attachment withImageNamed:(NSString *)imgName
{
// SAVE ATTACHMENT
[_attachments addObject:attachment];

// RESIZE CONTENT VIEW FOR INSERTINT NEW ATTACHMENT
_scrollView.contentSize = CGSizeMake([_attachments count]*70, 70);

CGFloat startX = (70.0f * ((float)[_attachments count] - 1.0f) + padding);
CGFloat startY = 370;
CGFloat width = 64;
CGFloat height = 64;

GalleryButton *btnAttachment = [[GalleryButton alloc] initWithFrame:CGRectMake(startX, startY, width, height) imageName:imgName];
btnAttachment.tag = [_attachments count];
btnAttachment.scrollParent = _scrollView;
btnAttachment.mainView = self.mainView;
btnAttachment.delegate = self;

if (attachment.type == 1){
}else if (attachment.type == 2){
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
    imageView.image=[UIImage imageNamed:@"mozambique-wenge"];
    [btnAttachment addSubview:imageView];
    [imageView release];
} else if (attachment.type == 3){
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
    imageView.image=[UIImage imageNamed:@"recyclebin.png"];
    [btnAttachment addSubview:imageView];
    [imageView release];
}

[_scrollView addSubview:btnAttachment];
[btnAttachment release];

}

- (void) removeAttachment:(GalleryButton *)button
{

}

#pragma mark - RELOAD DATA

- (void) reloadData
{

}

#pragma mark - GALLERY BUTTON DELEGATE

-(void) touchDown
{
[self.delegate didPressButton];
}

-(void) touchUp
{
[self.delegate didDropButton];
_scrollView.scrollEnabled = YES;
}

-(BOOL) isInsideRecycleBin:(GalleryButton *)button touching:(BOOL)finished;
{
CGPoint newLoc = [self convertPoint:self.recycleBin.frame.origin toView:self.mainView];
CGRect binFrame = self.recycleBin.frame;
binFrame.origin = newLoc;

if (CGRectIntersectsRect(binFrame, button.frame) == TRUE){
    if (finished){
        [self removeAttachment:button];
    }
    return YES;
}
else {
    return NO;
}

}

@end

GalleryButton.h
#import <UIKit/UIKit.h>

@protocol GalleryButtonDelegate;

@interface GalleryButton : UIView
{

id<GalleryButtonDelegate> delegate;

CGPoint _originalPosition;
CGPoint _originalOutsidePosition;

BOOL isInScrollview;

// PARENT VIEW WHERE THE VIEWS CAN BE DRAGGED
UIView *mainView;
// SCROLL VIEW WHERE YOU GONNA PUT THE THUMBNAILS
UIScrollView *scrollParent;
UIImageView *images;
}

@property (nonatomic, retain) id<GalleryButtonDelegate> delegate;
@property (nonatomic) CGPoint originalPosition;
@property (nonatomic, retain) UIView *mainView;
@property (nonatomic, retain) UIScrollView *scrollParent;
@property (nonatomic, retain) IBOutlet UIImageView *images;
@end

@protocol GalleryButtonDelegate
-(void) touchDown;
-(void) touchUp;
-(BOOL) isInsideRecycleBin:(GalleryButton *)button touching:(BOOL)finished;
@end

GalleryButton.m
#import <QuartzCore/QuartzCore.h>
#import "GalleryButton.h"
#import "GalleryScrollView.h"
#import "AttachmentItem.h"

@implementation GalleryButton

@synthesize delegate;
@synthesize originalPosition = _originalPosition;
@synthesize mainView, scrollParent;
@synthesize images;

- (id)init
{
self = [super init];
if (self) {
    // Initialization code here.
}

return self;
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self){

    isInScrollview  = YES;

    self.backgroundColor = [UIColor blackColor];
    self.layer.borderWidth = 2;
    self.layer.borderColor = [UIColor blackColor].CGColor;
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 5;
}
return self;
}

#pragma mark - DRAG AND DROP

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

[self.delegate touchDown];
self.originalPosition = self.center;
self.scrollParent.scrollEnabled = NO;

if (isInScrollview == YES) {
    CGPoint newLoc = CGPointZero;
    newLoc = [[self superview] convertPoint:self.center toView:self.mainView];
    _originalOutsidePosition = newLoc;

    //      [self.superview touchesCancelled:touches withEvent:event];
    [self removeFromSuperview];

    self.center = newLoc;
    [self.mainView addSubview:self];
    [self.mainView bringSubviewToFront:self];
    isInScrollview = NO;
}
else {
    ;
}

}

 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

[UIView beginAnimations:@"stalk" context:nil];
[UIView setAnimationDuration:.001];
[UIView setAnimationBeginsFromCurrentState:YES];

UITouch *touch = [touches anyObject];
self.center = [touch locationInView: self.superview];

[UIView commitAnimations];

if ([delegate isInsideRecycleBin:self touching:NO]){

}

}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

if ([delegate isInsideRecycleBin:self touching:YES]){

    CGRect myImageRect = CGRectMake(0, 0, 320, 300);
    images = [[UIImageView alloc] initWithFrame:myImageRect];
    [images setImage:[UIImage imageNamed:@"light-cherry.png"]];
    [self.mainView addSubview:images];
    [self.images viewWithTag:1];

    UIImageView * animation = [[UIImageView alloc] init];
    animation.frame = CGRectMake(self.center.x - 32, self.center.y - 32, 40, 40);

    animation.animationImages = [NSArray arrayWithObjects:
                                 [UIImage imageNamed: @"iconEliminateItem1.png"],
                                 [UIImage imageNamed: @"iconEliminateItem2.png"],
                                 [UIImage imageNamed: @"iconEliminateItem3.png"],
                                 [UIImage imageNamed: @"iconEliminateItem4.png"]
                                 ,nil];
    [animation setAnimationRepeatCount:1];
    [animation setAnimationDuration:0.35];
    [animation startAnimating];
    [self.mainView addSubview:animation];
    [animation bringSubviewToFront:self.mainView];
    [animation release];
    ;
    [UIView beginAnimations:@"goback" context:nil];
    [UIView setAnimationDuration:0.4f];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.center = _originalOutsidePosition;
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context:)];
    //        loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height);
    [UIView commitAnimations];

} else{
    [UIView beginAnimations:@"goback" context:nil];
    [UIView setAnimationDuration:0.4f];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.center = _originalOutsidePosition;
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context:)];
    //        loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height);
    [UIView commitAnimations];


}

[self.delegate touchUp];

}

-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([animationID isEqualToString:@"goback"] && finished) {
    [self removeFromSuperview];
    self.center = _originalPosition;
    [self.scrollParent addSubview:self];
    isInScrollview = YES;
}
}

@end

最佳答案

问题是您尚未声明自定义init方法:

- (id)initWithFrame:(CGRect)frame imageName:(NSString *)imageName;

GalleryButton.h中。您还没有在GalleryButton.m中实现它。也许您不是要在代码中完全使用此方法?

无论哪种方式,您都已经引用了它,并且Xcode已正确警告您它不存在(如果您构建并运行该代码,则会将无法识别的选择器发送给实例异常)。

关于iphone - Xcode错误语义错误值可能无法响应 'initWithFrame:image Name:',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13343946/

相关文章:

ios - <NSMutableURLRequest : 0x1c0c7ae0> { URL: (null) } in Objective C

ios - 如何在 View 上应用渐变模糊效果?

iphone - UIScrollView 阻止 View Controller 上的touchesBegan、touchesMoved、touchesEnded

iPhone Cocos2D CCColorLayers

iphone - 当用户返回 View Controller 时如何取消选择 uitableview 单元格

iphone - 使用 iOS 3.2 SDK 构建 iPhone 应用程序

ios - “[CP] Embed Pods Frameworks”构建脚本排序

iphone - Facebook 图形 API 与 native iPhone 应用程序

iphone - 如何计算UITextView中某个位置的NSString的NSRange

ios - 使用 UIProgressView Indicator 在 UITableView 中下载图像