I feel a bit of relief now, as I have finally figured out a solution to the 'silver' challenge from Chapter Six of 'iOS Programming'! It's taken me all day, but I did it! Essentially, I had a View Controller and a UIView created programmatically. The challenge was to create a UISegmentedControl to change the colors of the circles in the View. The variable that controlled the circle color was private, so I toyed around with making this public instead, then managed to create a new UIView object when the Segmented Control was selected. This worked OK, but I always lost the Segmented Control (due to not re-running loadView, which contained the code for the segmented view). Finally, I figured out that I had to create a variable for the color in my view controller, then rerun the loadView. The original loadView would automatically assign a lightGrayColor to the circles, but with the public variable in the View and a variable in the Controller, I was able to modify this to look to the variable first, then assign lightGrayColor if it was nil. This finally did the trick!
While I'm certain this isn't the most elegant solution to the problem, and is likely to be far too verbose (even by Objective-C standards!) to be useful, I'm proud that I stuck with it and found something that worked. I'll try to post this in GitHub, just in case anyone stumbles across this and needs help or would like to critique my work.
Onward and upward. Let's get going to Chapter Seven!
No comments:
Post a Comment