如何通过touch.view和isKindOfClass选择对象?

时间:2012-06-04 16:52:41

标签: objective-c class object touchesbegan

如果用touchesBegan方法中的情况,我会变得简单:

if ([touch.view isKindOfClass:[Direction class]])
{
    //select tapped object and do something...
}

我已查看了许多Direction个对象,当我点击其中一个时我想选择它,例如:

Direction *d = [touch.view].selectedObject; //something like that.

我可以在obj-C中这样做吗?或者我该如何正确地做到这一点?

1 个答案:

答案 0 :(得分:2)

if ([touch.view isKindOfClass:[Direction class]])
{
    //do something...
    Direction *d = (Direction*)[touch view];
}