开发者

How should I keep track of Buttons associated with a custom object

I'm making an App that will have multiple, identical, objects and I need to somehow keep track of the dynamic UI controls they create.

Example: I have 3 sets of 2 buttons and they are supposed to control a 开发者_如何学运维Player object, and when pressed I need to be able to figure out what Player object they are associated with.

My first thought was to make properties for the player object with the button ID's and compare the sender ID to that, but I cannot seem to get it to work right.

My Second thought was to make the Player object contain properties that ARE the UIButtons, ie p.button1 however that seems like it wouldn't be a good coding pattern. does anyone have any ideas on ways to accomplish this?


You could subclass UIButton and give it a Player variable and set this whenever you create your button, then compare the sender's player variable to your player.

Edit: another way to do it would be to set each Player's UIButtons tags to the same thing. ie. for Player1 make the tag for all the buttons associated with it 37 or something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜