Search code examples
iosxcodeminesweeper

iOS: Best way to implement a (Minesweeper style) grid of buttons


I've created a prototype of an iOS app. It's a game based on pressing a grid of buttons, with the labels changing depending on which buttons you pressed. In that sense it's a lot like Minesweeper.

I did this by making 64 individual buttons, and creating an outlet and an action for each by control-dragging to the .h file 128 times. It was a bit laborious. I then needed to copy (with minor changes) the code for each outlet and action 64 times. Again, laborious.

Now I want to make a new version with a bigger grid: 122 buttons. So I'd like to implement it more intelligently. Any ideas? Is there some sort of 'grid button' that could be used instead?


Solution

  • The best way would be to use a UICollectionView, its like a tableview but in gridformat(depending on ho you want to show your cells). Here's an example of http://www.raywenderlich.com/78550/beginning-ios-collection-views-swift-part-1

    And after a quick search i also found a GitHub repo with a minesweeper made with UICollectionView: https://github.com/AdamGluck/minesweeper