2010-11-06 88 views
0

現在我知道NSEvent不存在於ios上 - 我需要做什麼才能捕獲像touchUpInside這樣的事件並使其調用我的方法來處理它,而無需Interface Builder?在ios中連接觸摸事件

我覺得這就像問我怎麼事件鏈接到沒有IB的出口...

我知道這是可以做到的,但我無法找到任何說明如何 - 除了蘋果只例子那使用NSEvent。

回答

1

看看這個方法在UIControl:

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents 

每個不同的事件類型的具有恆定的,如UIControlEventTouchUpInside。下面是使用它的一個例子:

[addButton addTarget:self action:@selector(increment:) forControlEvents:UIControlEventTouchDown]; 

Look here爲controlEvents的值,在常量部分中列出。