这就是问题所在:我将一个指向对象的指针传递给performSelector:withObject
via [NSValue valueWithPointer:]
,例如:
// GVertex is NSObject subclass
GVertex *vertex = [[GVertex alloc] initWithX:5.0f andY:4.5f]];
GVertex **vertexPtr = &vertex;
// later in code when I need to process the vertex
[self performSelector:@selector(processVertex:) withObject:[NSValue valueWithPointer:vertexPtr]];
然后在我的processVertex:(NSValue *)vertexValue
方法中,我想获取传递的顶点,我这样做:
- (void)parseVertex:(NSValue *)vertexValue
{
GVertex *vertex = (GVertex *)[vertexValue pointerValue];
...
[vertex setFlags:32]; <<-- This gives me EXC_BAD_ACCESS
...
}
我已经尝试了许多 (*) 和 (&) 的组合,但无法让它发挥作用。我究竟做错了什么 ?谢谢。