我需要释放手势识别器吗?
如果我将手势识别器添加到名为 cell
的表格单元格中,例如:
UILongPressGestureRecognizer *_longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(cellGestureRecognized:)];
_longPressRecognizer.allowableMovement = 20;
_longPressRecognizer.minimumPressDuration = 1.0f;
[cell addGestureRecognizer:_longPressRecognizer];
[_longPressRecognizer release], _longPressRecognizer = nil;
我是否需要在某个时候在此单元格上手动调用 -removeGestureRecognizer:
,或者手势识别器是否需要手动调用 -removeGestureRecognizer:
当电池不再使用时,将其移除并释放给我吗?
If I add a gesture recognizer to a table cell called cell
, e.g.:
UILongPressGestureRecognizer *_longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(cellGestureRecognized:)];
_longPressRecognizer.allowableMovement = 20;
_longPressRecognizer.minimumPressDuration = 1.0f;
[cell addGestureRecognizer:_longPressRecognizer];
[_longPressRecognizer release], _longPressRecognizer = nil;
Do I need to manually call -removeGestureRecognizer:
on this cell at some point, or does the gesture recognizer get removed and released for me when the cell is no longer used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
手势识别器被添加到视图的内部 NSMutableArray 中。一旦视图被释放,这个数组就会被释放。因此,不需要手动调用
-removeGestureRecognizer:
。The gesture recognizers are added to an internal NSMutableArray of the view. This array will be released once the view is deallocated. Thus
-removeGestureRecognizer:
doesn't need to be called manually.