Silver Challenge -- add button?



  1. What does add a button to the MapViewController mean? Add it to the SegmentedControl? Add it to some random spot?

  2. Are we supposed to add the button programmatically? Or in IB (Interface Builder)? The chapter is titled “Programmatic Views”.

Issues to consider.


I did it programmatically and spent a long, frustrating time trying to sort out the layout programmatically. In the end, I managed to get a button in the place I wanted it, but I got bored trying to make the button look decent and just left it as a boring, green rectangle.

Before that, I tried to add the button via IB, but ultimately couldn’t work out how to make the button stay there when you then replace the view with the map view (I assume programmatically takes precendence over IB?).

If I’m being honest, as good as the book is, I don’t think the challenges give you enough guidance. Perhaps they could do with some more hints / pseudocode / guides to the methods used and then leaving us up to completing the details.


I’m doing everything programmatically, too.

Ah. Maybe that is what the authors intended–if you try to take the easy way out, you are punished! Interesting issue. The UIViewController docs have this to say:


If you use Interface Builder to create your views and initialize the view controller, you must not override this method.[/quote]

Getting a button configured was a chore. I was certainly surprised to discover that specifying a button type of RoundedRect did not produce a rounded rect button! RoundedRect is just an alias for System(I printed out their rawValues). Why the heck would anyone need such a misleading alias?

I think that was sort of a good exercise, as it concentrates on one thing, and it forces you to track down all the methods for configuring a button–which makes you appreciate IB! And, you can stop configuring at whatever point your doc-fu begins failing. Finally, you can add constraints to the button by mimicking what was done in the chapter for the SegmentedControl–and possibly constraining the button to a different location, say, the bottom left corner.

I think adding 3 or 4 exercises per chapter concentrating solely on the Swift language would have been nice. Perhaps slowly bringing us up to speed on optionals. But, yeah, I get what you are saying: the exercises are difficult.


Found a link with some relevant info that helped me along with the button creation and design: