Multiplying interface elements?

Hello there,

First post, first question… Currently developing my first “big app”, I’m looking for the (best) way to duplicate elements and their usage.

Here’s the two situations where I need it to happen…

  1. Multiple players

My app asks for name, a number, a color for X players. Depending on X I have to duplicate rows and then get access to the variables like “name_1”, “name_2”, and so on.
For now, I’m managing two players by duplicating fields in the storyboard and hiding the one I don’t need. It works but it’s not clean and will become a problem with 5 players…

How do I create / duplicate lines programmatically and maintain access to the data ?

  1. Multiple scores
    After the game is created, I will ask the user to enter data on several categories for each player.

I have a column with 7 different textfields for each players where the user will enter corresponding values.
Same question as above but maybe same answer ?

Thanks a lot for any help !

Ben

Check out UICollectionView or UITableView.

You can define a custom cell with all of your interface elements for a single player, and then set your collection/table size to the desired number of players. Store all your player info in an array and use that array to feed the cells in your collection/table.

We’ve got a bunch of tutorials on this site that can help you get started. Here is one for UICollectionView.

Have fun!

Thanks for The reply, I begin ton undrestand the idea.

But is it possible for the players’ scores, that the UICollection cells contain a single column table view ?

Most important how do I link actions to the inner elements (fields, buttons, etc) that are specific to each player (ie altering his score) ?

Thx