2010-11-06 89 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的值,在常量部分中列出。