2014-11-23 75 views
-2

我試圖創建一個程序,當我點擊屏幕時,警報將彈出.. 因此,我將UIView更改爲UIControl,並創建一個IBAction方法當點擊屏幕時,然後我發現了一個方法在互聯網上打印水龍頭位置。調用IBAction方法

這是我的代碼:

-(IBAction) Touch:(id)sender{ 
    [self touchesBegan]; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *myTouch = [[touches allObjects] objectAtIndex: 0]; 
    CGPoint currentPos = [myTouch locationInView: self]; 
    NSLog(@"Point in myView: (%f,%f)", currentPos.x, currentPos.y); 
} 

及給予的我一個錯誤... 怎麼辦?!?!

+0

其錯誤它給你? – 2014-11-23 16:24:00

+1

'該怎麼做?!?!'告訴我們這個錯誤究竟是什麼將是我能想象的最好的起點。 – nhgrif 2014-11-23 16:24:02

+0

我知道你的錯誤是什麼,刪除[self touchesBegan]你是1.調用這個方法沒有必要的參數,所以你可能會得到無法識別的選擇器發送到實例,第二個uiview自己調用這個方法,你只需要重寫它 – 2014-11-23 16:25:08

回答

1

刪除您「觸摸」的方法[self touchesBegan]

1. calling this method without the necessary parameters, so you are 
probably getting unrecognized selector sent to instance, 
2. the uiview calls this method on its own, you just need to override it