“iPhone应用程序编程指南”的“事件处理”部分中的示例代码“处理复杂的多点触控序列”提供了一个不完整的示例,假设读者知道填充空白。我知道的很多,如果没有一些澄清,我就不知道这么做。
在清单3-6中,我假设touchBeginPoints
是类型为CFDictionaryRef
的成员属性。正确的吗?
在同一个示例中,我们使用的是malloc()
,因此我假设我们需要稍后调用free()
。我的问题是我什么时候可以解放?我应该free()
/ touchesEnded:
touchesCancelled:
中的各个点吗?我该怎么办? (我假设我需要阅读枚举CFDictionaryRef
)或我free(touchBeginPoints);
方法中的dealloc:
?
最后,在清单3-7中有一个compareAddress:
方法。我将如何(以及在何处)实施该目标?
更新找到the answer到最后一个。
答案 0 :(得分:1)
free
键,您可能希望在创建字典时传入自定义版本回调。释放字典本身时,将为字典中的每个元素调用键释放回调。 (有关详细信息,请参阅CFMutableDictionaryCreate
的最后两个参数。) compareAddress:
看起来像:
@interface UITouch (TouchSorting)
- (NSComparisonResult)compareAddress:(id)obj;
@end
@implementation UITouch (TouchSorting)
- (NSComparisonResult)compareAddress:(id)obj {
if ((void *)self < (void *)obj) return NSOrderedAscending;
else if ((void *)self == (void *)obj) return NSOrderedSame;
else return NSOrderedDescending;
}
@end