Get all instances of a class in objective c?

前端 未结 4 1538
不思量自难忘°
不思量自难忘° 2021-01-15 11:58

I have a UIView that has many instances and each one of them has a UIRecognizer.

When on of them is tapped I want to remove all the recognizers of the others.

<
4条回答
  •  醉酒成梦
    2021-01-15 12:13

    I have two ideas:

    1/ Create a class array with all the instances static NSArray* instances;, register them when initializing, unregister when deallocating. The array should have only weak references, otherwise they will never be deallocated.

    2/ NSNotification. All instances can wait for a notification and if you tap, you send the notification.

提交回复
热议问题