I am coding in the latest xcode in Objective-C and I have been pretty much stuck last two days.
I am making an application that will allow the users to select what color clothing they are wearing. So for example, if I am wearing a black and white shirt, I can choose clothing = shirt and colours = black and white.
Here is a screen shot of how my app looks like: (everything you see here are UIButtons so you can click them and for colours, I have it set up so the colours you have chosen will highlight)
![my app]: https://i.stack.imgur.com/pBFud.png “myApp”
so in the first image, you would choose your clothing and once you hit the button, the second view will come up and in here, you would choose the colours.
So far so good. But I run into some problems when I want to use the colours chosen to bring back to the first view. If I picked black and white for the colours of my shirt, I want my app to bring back that data and change the “shirt” button’s background colour to change to black and white to indicate to the users those are the colours you have chosen. ‘
Here are my codes so far.
changeClothes.h (first view): http://pastebin.com/xPMNAnCY
changeClothes.m: http://pastebin.com/MdjMPK6r
chooseColors.h (second view): http://pastebin.com/Zb4aXvzV
chooseColors.m: http://pastebin.com/RHTxfwW5
Any help would be appreciated.
Many, many, many thanks in advance.
You could work with the delegation pattern!
Define a protocol for your chooseColors class and make the changeClothes class implement this protocol. changeClothes class then works as a delegate of chooseColors class. In chooseColors class, when a color is selected via button, call the delegate with this event! Back in changeClothes class you can dismiss the modal chooseColors controller and perform some actions in changeClothes controller according to the selected color.
More on the delegation pattern: Cocoa Core Competencies
(On the bottom you have a reference to a example project from apple)
Also please take a look at the coding guidelines for cocoa!
You named your classes wrongly, see: Coding Guidelines for Cocoa