在下面的代碼中,我定義了一個函數來創建箭頭(如圖像)並將這些箭頭添加到視圖中。但是,我收到了一條警告,說Undeclared selector 'method'
。有人可以建議另一種方法來避免這種警告將字符串參數傳遞給UITapGestureRecognizer動作
-(void)createArrow:(NSString*)direction View:(UIView*)view
{
int x,y;
NSString *img;
NSString *method;
if ([direction isEqualToString:@"up"]){
x = 55;
y = 6;
_arrow = _arrowUp;
method = @"upTap";
img = @"up-arrow.png";
}else if ([direction isEqualToString:@"down"]){
x = 55;
y = 70;
_arrow = _arrowDown;
method = @"downTap";
img = @"down-arrow.png";
}else if ([direction isEqualToString:@"left"]){
x = 22;
y = 39;
_arrow = _arrowLeft;
method = @"leftTap";
img = @"left-arrow.png";
}else if ([direction isEqualToString:@"right"]){
x = 90;
y = 39;
_arrow = _arrowRight;
method = @"rightTap";
img = @"right-arrow.png";
}
_arrow = [[UIImageView alloc] initWithFrame: CGRectMake(x, y, 27, 27)];
[_arrow setImage:[UIImage imageNamed:img]];
UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(method)];
[_arrow setUserInteractionEnabled:YES];
[_arrow addGestureRecognizer:gest];
[view addSubview:_arrow];
}