2014-11-03 73 views
-1

当我创建UITouch的一类类这是我的代码:崩溃使用类别

- (id)initInView:(UIView *)view; 
{ 
CGRect frame = view.frame;  
CGPoint centerPoint = CGPointMake(frame.size.width * 0.5f, frame.size.height * 0.5f); 
return [self initAtPoint:centerPoint inView:view]; 
} 

- (id)initAtPoint:(CGPoint)point inWindow:(UIWindow *)window; 
{ 
self = [super init]; 
if (self == nil) { 
    return nil; 
} 

// Create a fake tap touch 
_tapCount = 1; 
_locationInWindow = point; 
_previousLocationInWindow = _locationInWindow; 

UIView *hitTestView = [window hitTest:_locationInWindow withEvent:nil]; 

_window = [window retain]; 
_view = [hitTestView retain]; 
if ([self respondsToSelector:@selector(setGestureView:)]) { 
    [self setGestureView:hitTestView]; 
} 
_phase = UITouchPhaseBegan; 
_touchFlags._firstTouchForView = 1; 
_touchFlags._isTap = 1; 
_timestamp = [[NSProcessInfo processInfo] systemUptime]; 

return self; 
} 

- (id)initAtPoint:(CGPoint)point inView:(UIView *)view; 
{ 
return [self initAtPoint:[view.window convertPoint:point fromView:view] inWindow:view.window]; 
} 

- (void)setPhase:(UITouchPhase)phase; 
{ 
_phase = phase; 
_timestamp = [[NSProcessInfo processInfo] systemUptime]; 
} 

,但是当我把它称为我得到这个崩溃 - [UITouch initAtPoint:inView:]:无法识别的选择发送到实例 我该如何解决这个问题?

+0

为什么投降? – HDNZ 2014-11-04 07:55:30

回答

1

你说你创建了一个类别,但没有包括你的类别的定义。

它应该是这个样子:

//UITouch+customInitMethods.h 


@interface UITouch (customInitMethods) 

- (id)initInView:(UIView *)view; 

- (id)initAtPoint:(CGPoint)point inWindow:(UIWindow *)window; 

- (id)initAtPoint:(CGPoint)point inView:(UIView *)view; 

@end 

然后您实现:

#import "UITouch+customInitMethods.h" 

@implementation UITouch (customInitMethod) 

//Your method implementations go here. 

@end 

确保你的类文件的.m文件目标复选框被设置为包括类别在您的应用程序目标。

然后,您需要在任何想要使用自定义init方法的文件中#import UITouch + customInitMethods.h。

+0

ü保存我的一天我的类别的目标没有设置:) – HDNZ 2014-11-03 15:05:26

+0

很高兴我能帮上忙。我已经做了不止一次... – 2014-11-03 17:55:47