I want to give my UIButton’s custom subclasses so that each button keeps track of what button is to the left, right, top, and bottom of it.
For example (on a 6×5 button layout), i want button my button button23 (in location (2,3)) to have button23.left = button22 button23.right = button24 button23.top = button33 and button23.bottom = button13. What’s the best way to go about this?
If you want to create a 2 dimensional linked list of controls then you can do that. But subclassing is not going to help you much except to hide the actual structure inside UIButton subclasses.
You need a class to manage the creation of this structure, Interface Builder wont do it for you. So if you are going to subclass create a subclass of UIButton with Two linked list nodes prev and next for each dimension then create all your buttons manually and set the linked list pointers to the appropriate controls.
In the vertical case prev and next will mean top or bottom.
If you dont subclass just create a two dimensional linked list manager and add the nodes and pointers to the nodes related nodes externally.