Generating UIButtons from a loop, part 2


creating a second part of the tutorial as some folks wanted to do this trick with a few variations.
( link to part I )

As a start a Navigation controller got involved 🙂
So you end up with a problem where buttons would disappear as you go back and forth.
Solution for this is posted at the end of part 1.
However there was someone who wanted to have different main button and the later created buttons.

Here is a solution to that.
First of all embed your project in a Navigation Controller, so you end up with something like that :


Then, change your project(ViewController.swift) to this:

Then, once you run the project, you should see this:

Once you add some buttons:

Now, if you go back and forth the buttons should still be there.

I was actually gonna add another example on how to just add the buttons to a new UIView and
just add it later, however I found some problems with doing that and a navigation controller, so that is probably the best way of doing it ( at least for now 😉 )

Cheers !